Mercurial > octave
annotate libinterp/corefcn/pr-output.cc @ 27466:6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
* pr-output.cc (make_real_format, make_real_matrix_format, make_complex_format,
make_complex_matrix_format, make_range_format): Switch to scientific notation
when number of significant digits (ld + rd) exceeds 1.5 * output_precision.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 01 Oct 2019 22:06:01 -0700 |
parents | 36b610122086 |
children | d503426130bf |
rev | line source |
---|---|
1 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
26205
diff
changeset
|
3 Copyright (C) 1993-2019 John W. Eaton |
1 | 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> |
1343 | 28 |
3503 | 29 #include <iomanip> |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
30 #include <limits> |
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
31 #include <list> |
5765 | 32 #include <sstream> |
1728 | 33 #include <string> |
34 | |
4655 | 35 #include "Array-util.h" |
453 | 36 #include "CMatrix.h" |
1 | 37 #include "Range.h" |
2926 | 38 #include "cmd-edit.h" |
1352 | 39 #include "dMatrix.h" |
2891 | 40 #include "lo-mappers.h" |
2317 | 41 #include "mach-info.h" |
1651 | 42 #include "oct-cmplx.h" |
26111
3e44ed9d50b6
Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26009
diff
changeset
|
43 #include "oct-string.h" |
4153 | 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 | |
27454
43ece0b8318b
Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents:
27453
diff
changeset
|
127 // the desired behavior (truncation). There may be a gnulib replacement. |
20946 | 128 |
129 // ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO, | |
130 // IEC. 2003 . "the binary % operator yields the remainder from the | |
131 // division of the first expression by the second. .... If both | |
132 // operands are nonnegative then the remainder is nonnegative; if not, | |
133 // 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
|
134 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
135 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
136 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
137 static inline int |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
138 engineering_exponent (T x) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
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 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
144 T absval = (x < 0 ? -x : x); |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
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 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
150 if (logabsval < 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 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
159 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
160 static inline int |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
161 num_digits (T x) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
162 { |
11450
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
163 return 1 + (print_eng |
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
164 ? engineering_exponent (x) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
165 : 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
|
166 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
167 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
168 template <typename T> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
169 int |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
170 pr_engineering_float<T>::exponent (void) const |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
171 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
172 return engineering_exponent (m_val); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
173 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
174 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
175 template <typename T> |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
176 T |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
177 pr_engineering_float<T>::mantissa (void) const |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
178 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
179 return m_val / std::pow (static_cast<T> (10), exponent ()); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
180 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
181 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
182 template <typename T> |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
183 std::ostream& |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
184 operator << (std::ostream& os, const pr_engineering_float<T>& pef) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
185 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
186 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
|
187 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
188 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
|
189 |
27183
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
190 if (real_fmt.width () >= 0) |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
191 os << std::setw (real_fmt.width () - real_fmt.exponent_width ()); |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
192 |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
193 if (real_fmt.precision () >= 0) |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
194 os << std::setprecision (real_fmt.precision ()); |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
195 |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
196 os.flags (real_fmt.format_flags ()); |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
197 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
198 os << pef.mantissa (); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
199 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
200 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
|
201 if (ex < 0) |
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 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
|
204 ex = -ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
205 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
206 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
207 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
|
208 |
27183
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
209 os << std::setw (real_fmt.exponent_width () - 2) |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
210 << 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
|
211 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
212 return os; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
213 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
214 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
215 template <typename T> |
3608 | 216 std::ostream& |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
217 operator << (std::ostream& os, const pr_formatted_float<T>& pff) |
3608 | 218 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
219 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
|
220 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
221 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
|
222 |
27183
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
223 if (real_fmt.width () >= 0) |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
224 os << std::setw (real_fmt.width ()); |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
225 |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
226 if (real_fmt.precision () >= 0) |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
227 os << std::setprecision (real_fmt.precision ()); |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
228 |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
229 os.flags (real_fmt.format_flags ()); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
230 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
231 os << pff.m_val; |
3608 | 232 |
233 return os; | |
234 } | |
235 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
236 template <typename T> |
6788 | 237 std::ostream& |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
238 operator << (std::ostream& os, const pr_rational_float<T>& prf) |
6788 | 239 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
240 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
|
241 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
242 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
|
243 |
27183
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
244 int fw = (rat_string_len > 0 ? rat_string_len : real_fmt.width ()); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
245 std::string s = rational_approx (prf.m_val, fw); |
6788 | 246 |
247 if (fw >= 0) | |
248 os << std::setw (fw); | |
249 | |
27183
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
250 os.flags (real_fmt.format_flags ()); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
251 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
252 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
|
253 os << '*'; |
6788 | 254 else |
255 os << s; | |
256 | |
257 return os; | |
258 } | |
259 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
260 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
261 static inline T |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
262 pr_max_internal (const MArray<T>& m) |
1 | 263 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
264 // We expect a 2-d array. |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
265 assert (m.ndims () == 2); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
266 |
5275 | 267 octave_idx_type nr = m.rows (); |
268 octave_idx_type nc = m.columns (); | |
1 | 269 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
270 T result = std::numeric_limits<T>::lowest (); |
1 | 271 |
5748 | 272 bool all_inf_or_nan = true; |
273 | |
5275 | 274 for (octave_idx_type j = 0; j < nc; j++) |
275 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 276 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
277 T val = m(i,j); |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
278 if (! octave::math::isfinite (val)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 continue; |
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 all_inf_or_nan = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
282 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
283 if (val > result) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
284 result = val; |
1 | 285 } |
3608 | 286 |
5748 | 287 if (all_inf_or_nan) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
288 result = 0; |
5748 | 289 |
1 | 290 return result; |
291 } | |
292 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
293 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
294 static inline T |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
295 pr_min_internal (const MArray<T>& m) |
1 | 296 { |
5275 | 297 octave_idx_type nr = m.rows (); |
298 octave_idx_type nc = m.columns (); | |
1 | 299 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
300 T result = std::numeric_limits<T>::max (); |
1 | 301 |
5748 | 302 bool all_inf_or_nan = true; |
303 | |
5275 | 304 for (octave_idx_type j = 0; j < nc; j++) |
305 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 306 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
307 T val = m(i,j); |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
308 if (! octave::math::isfinite (val)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
309 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
311 all_inf_or_nan = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 if (val < result) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
314 result = val; |
1 | 315 } |
3608 | 316 |
5748 | 317 if (all_inf_or_nan) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
318 result = 0; |
5748 | 319 |
1 | 320 return result; |
321 } | |
322 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
323 template <typename> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
324 struct pr_output_traits |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
325 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
326 static const int digits10; |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
327 static const int max_field_width; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
328 }; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
329 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
330 template <> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
331 struct pr_output_traits<double> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
332 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
333 static const int digits10; |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
334 static const int max_field_width; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
335 }; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
336 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
337 const int pr_output_traits<double>::digits10 = 16; |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
338 const int pr_output_traits<double>::max_field_width = 21; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
339 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
340 template <> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
341 struct pr_output_traits<float> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
342 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
343 static const int digits10; |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
344 static const int max_field_width; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
345 }; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
346 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
347 const int pr_output_traits<float>::digits10 = 8; |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
348 const int pr_output_traits<float>::max_field_width = 13; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
349 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
350 // FIXME: it would be nice to share more code among these functions,.. |
1658 | 351 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
352 // Works for double and float. |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
353 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
354 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
355 static inline float_display_format |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
356 make_real_format (int digits, bool inf_or_nan, bool int_only) |
1 | 357 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
358 float_format fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
359 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
360 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 361 |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
362 int fw = 0, ld = 0, rd = 0; |
1 | 363 |
6788 | 364 if (rat_format) |
365 { | |
366 fw = 0; | |
367 rd = 0; | |
368 } | |
369 else if (bank_format) | |
1 | 370 { |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
371 fw = (digits < 0 ? 4 : digits + 3); |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
372 if (inf_or_nan) |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
373 fw = 3; |
1 | 374 rd = 2; |
375 } | |
1282 | 376 else if (hex_format) |
377 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
378 fw = 2 * sizeof (T); |
1282 | 379 rd = 0; |
380 } | |
1309 | 381 else if (bit_format) |
382 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
383 fw = 8 * sizeof (T); |
1309 | 384 rd = 0; |
385 } | |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
386 else if (inf_or_nan) |
1 | 387 { |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
388 fw = 3; |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
389 } |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
390 else if (int_only) |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
391 { |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
392 fw = digits; |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
393 ld = digits; |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
394 rd = 0; |
1 | 395 } |
396 else | |
397 { | |
398 if (digits > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
399 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 ld = digits; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
401 rd = (prec > digits ? prec - digits : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
402 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
403 else if (digits < 0) |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
404 { |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
405 ld = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
406 rd = (prec > digits ? prec - digits : prec); |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
407 } |
1 | 408 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
409 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
410 ld = 1; |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
411 rd = (prec > digits ? prec - 1 : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
412 } |
1 | 413 |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
414 fw = ld + 1 + rd; |
1 | 415 } |
416 | |
6788 | 417 if (! (rat_format || bank_format || hex_format || bit_format) |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
418 && (print_e || print_g || print_eng |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
419 || ld + rd > pr_output_traits<T>::digits10 |
27466
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
420 || fw > pr_output_traits<T>::max_field_width |
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
421 || ld + rd > (1.5 * prec))) |
1 | 422 { |
4509 | 423 if (print_g) |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
424 fmt = float_format (prec, prec); |
4509 | 425 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
426 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
427 // e+ddd |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
428 int ex = 5; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
429 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
430 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
431 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
432 // -ddd. |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
433 fw = 1 + prec + ex; |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
434 if (inf_or_nan) |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
435 { |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
436 fw = 3; |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
437 ex = 0; |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
438 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
439 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
|
440 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
441 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
442 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
443 // -d. |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
444 fw = prec + ex; |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
445 if (inf_or_nan) |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
446 { |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
447 fw = 3; |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
448 ex = 0; |
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
449 } |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
450 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
|
451 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
452 } |
3608 | 453 |
1 | 454 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
455 fmt.uppercase (); |
1 | 456 } |
5086 | 457 else if (! bank_format && (inf_or_nan || int_only)) |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
458 fmt = float_format (fw, ld); |
1 | 459 else |
3608 | 460 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 461 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
462 return float_display_format (fmt); |
1 | 463 } |
464 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
465 // Works for double and float. |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
466 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
467 template <typename T> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
468 float_display_format |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
469 make_scalar_format (const T& val) |
1658 | 470 { |
471 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
472 return float_display_format (); |
1658 | 473 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
474 bool inf_or_nan = (octave::math::isinf (val) || octave::math::isnan (val)); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
475 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
476 bool int_only = (! inf_or_nan && octave::math::x_nint (val) == val); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
477 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
478 T val_abs = (val < 0 ? -val : val); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
479 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
480 int digits = (inf_or_nan || val_abs == 0) ? 0 : num_digits (val_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
481 |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
482 return make_real_format<T> (digits, inf_or_nan, int_only); |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
483 } |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
484 |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
485 template <> |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
486 float_display_format |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
487 make_format (const double& d) |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
488 { |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
489 return make_scalar_format (d); |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
490 } |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
491 |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
492 template <> |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
493 float_display_format |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
494 make_format (const float& f) |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
495 { |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
496 return make_scalar_format (f); |
1 | 497 } |
498 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
499 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
500 static inline float_display_format |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
501 make_real_matrix_format (int x_max, int x_min, bool inf_or_nan, |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
502 int int_or_inf_or_nan) |
1 | 503 { |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
504 T scale = ((x_max == 0 || int_or_inf_or_nan) |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
505 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
506 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
507 float_format fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
508 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
509 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 510 |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
511 int fw = 0, ld = 0, rd = 0; |
1 | 512 |
6788 | 513 if (rat_format) |
514 { | |
515 fw = 9; | |
516 rd = 0; | |
517 } | |
518 else if (bank_format) | |
1 | 519 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
520 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
|
521 fw = (digits <= 0 ? 5 : digits + 4); |
1 | 522 rd = 2; |
523 } | |
1282 | 524 else if (hex_format) |
525 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
526 fw = 2 * sizeof (T); |
1282 | 527 rd = 0; |
528 } | |
1309 | 529 else if (bit_format) |
530 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
531 fw = 8 * sizeof (T); |
1309 | 532 rd = 0; |
533 } | |
4509 | 534 else if (Vfixed_point_format && ! print_g) |
3268 | 535 { |
27453
05f84e5cb08a
Display correct number of digits with "format long" and fixed_point_format (bug #56938).
Rik <rik@octave.org>
parents:
27451
diff
changeset
|
536 rd = prec - 1; |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
537 fw = rd + 3; |
5748 | 538 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
539 fw = 4; |
3268 | 540 } |
1715 | 541 else if (int_or_inf_or_nan) |
1 | 542 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
543 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
|
544 fw = (digits <= 0 ? 2 : digits + 1); |
5748 | 545 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
546 fw = 4; |
3682 | 547 rd = fw; |
1 | 548 } |
549 else | |
550 { | |
551 int ld_max, rd_max; | |
552 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
553 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
554 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
555 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
|
556 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
557 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
558 else if (x_max < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
559 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
560 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
561 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
|
562 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
563 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
564 else |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
565 { |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
566 ld_max = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
567 rd_max = (prec > 1 ? prec - 1 : prec); |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
568 x_max = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
569 } |
1 | 570 |
571 int ld_min, rd_min; | |
572 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
573 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
574 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
575 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
|
576 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
577 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
578 else if (x_min < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
579 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
580 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
581 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
|
582 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
583 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
584 else |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
585 { |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
586 ld_min = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
587 rd_min = (prec > 1 ? prec - 1 : prec); |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
588 x_min = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
589 } |
1 | 590 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
591 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
|
592 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 593 |
5832 | 594 fw = 1 + ld + 1 + rd; |
5748 | 595 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
596 fw = 4; |
1 | 597 } |
598 | |
6788 | 599 if (! (rat_format || bank_format || hex_format || bit_format) |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
600 && (print_e || print_eng || print_g |
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
601 || (! Vfixed_point_format |
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
602 && (ld + rd > pr_output_traits<T>::digits10 |
27466
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
603 || fw > pr_output_traits<T>::max_field_width |
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
604 || ld + rd > (1.5 * prec))))) |
1 | 605 { |
4509 | 606 if (print_g) |
27439
251056aeba5d
Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents:
27434
diff
changeset
|
607 fmt = float_format (prec+6, prec); |
4509 | 608 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
609 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
610 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
611 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
|
612 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
613 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
614 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
615 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
616 fw = 4 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
617 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
|
618 fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
619 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
|
620 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
621 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
622 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
623 fw = 2 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
624 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
|
625 fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
626 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
|
627 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
628 } |
3608 | 629 |
1 | 630 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
631 fmt.uppercase (); |
1 | 632 } |
5086 | 633 else if (! bank_format && int_or_inf_or_nan) |
3611 | 634 fmt = float_format (fw, rd); |
1 | 635 else |
3608 | 636 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 637 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
638 return float_display_format (scale, fmt); |
1 | 639 } |
640 | |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
641 template <typename MT> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
642 static inline float_display_format |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
643 make_matrix_format (const MT& m) |
1658 | 644 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
645 assert (m.ndims () == 2); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
646 |
1658 | 647 if (free_format) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
648 return float_display_format (); |
1658 | 649 |
2387 | 650 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658 | 651 |
2387 | 652 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658 | 653 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
654 MT m_abs = m.abs (); |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
655 |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
656 typedef typename MT::element_type ELT_T; |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
657 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
658 ELT_T max_abs = pr_max_internal (m_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
659 ELT_T min_abs = pr_min_internal (m_abs); |
1658 | 660 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
661 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
662 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
663 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
664 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
665 return make_real_matrix_format<ELT_T> (x_max, x_min, inf_or_nan, |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
666 int_or_inf_or_nan); |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
667 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
668 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
669 template <> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
670 float_display_format |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
671 make_format (const Matrix& m) |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
672 { |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
673 return make_matrix_format (m); |
1 | 674 } |
675 | |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
676 template <> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
677 float_display_format |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
678 make_format (const FloatMatrix& m) |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
679 { |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
680 return make_matrix_format (m); |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
681 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
682 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
683 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
684 static inline float_display_format |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
685 make_complex_format (int x_max, int x_min, int r_x, |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
686 bool inf_or_nan, int int_only) |
1 | 687 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
688 float_format r_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
689 float_format i_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
690 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
691 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 692 |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
693 int i_fw = 0, r_fw = 0, ld = 0, rd = 0; |
1 | 694 |
6788 | 695 if (rat_format) |
696 { | |
697 i_fw = 0; | |
698 r_fw = 0; | |
699 rd = 0; | |
700 } | |
701 else if (bank_format) | |
1 | 702 { |
703 int digits = r_x; | |
704 i_fw = 0; | |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
705 r_fw = (digits <= 0 ? 5 : digits + 4); |
1 | 706 rd = 2; |
707 } | |
1282 | 708 else if (hex_format) |
709 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
710 r_fw = 2 * sizeof (T); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
711 i_fw = 2 * sizeof (T); |
1282 | 712 rd = 0; |
713 } | |
1309 | 714 else if (bit_format) |
715 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
716 r_fw = 8 * sizeof (T); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
717 i_fw = 8 * sizeof (T); |
1309 | 718 rd = 0; |
719 } | |
1658 | 720 else if (inf_or_nan || int_only) |
1 | 721 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
722 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
|
723 i_fw = (digits <= 0 ? 1 : digits); |
5945 | 724 r_fw = i_fw + 1; |
725 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
726 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
727 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
728 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
729 } |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
730 |
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
731 if (int_only) |
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
732 { |
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
733 ld = digits; |
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
734 rd = 0; |
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
735 } |
1 | 736 } |
737 else | |
738 { | |
739 int ld_max, rd_max; | |
740 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
741 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
742 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
743 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
|
744 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
745 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
746 else if (x_max < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
747 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
748 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
749 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
|
750 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
751 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
752 else |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
753 { |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
754 ld_max = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
755 rd_max = (prec > 1 ? prec - 1 : prec); |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
756 x_max = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
757 } |
1 | 758 |
759 int ld_min, rd_min; | |
760 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
761 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
762 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
763 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
|
764 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
765 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
766 else if (x_min < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
767 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
768 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
769 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
|
770 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
771 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
772 else |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
773 { |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
774 ld_min = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
775 rd_min = (prec > 1 ? prec - 1 : prec); |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
776 x_min = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
777 } |
1 | 778 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
779 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
|
780 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 781 |
5945 | 782 i_fw = ld + 1 + rd; |
783 r_fw = i_fw + 1; | |
1 | 784 } |
785 | |
6788 | 786 if (! (rat_format || bank_format || hex_format || bit_format) |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
787 && (print_e || print_eng || print_g |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
788 || ld + rd > pr_output_traits<T>::digits10 |
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
789 || r_fw > pr_output_traits<T>::max_field_width |
27466
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
790 || i_fw > pr_output_traits<T>::max_field_width |
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
791 || ld + rd > (1.5 * prec))) |
1 | 792 { |
4509 | 793 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
794 { |
27439
251056aeba5d
Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents:
27434
diff
changeset
|
795 int width = prec + 6; |
27429
e0134184c1fd
Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
796 r_fmt = float_format (width, prec); |
e0134184c1fd
Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
797 i_fmt = float_format (width, prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 } |
4509 | 799 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
800 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
801 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
802 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
|
803 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
804 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
805 if (print_eng) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
806 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
807 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
|
808 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
|
809 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
|
810 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
811 i_fw = 5; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
812 r_fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
813 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
814 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
|
815 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
|
816 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
817 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
818 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
819 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
|
820 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
|
821 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
|
822 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
823 i_fw = 3; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
824 r_fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
825 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
826 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
|
827 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
|
828 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
829 } |
3608 | 830 |
1 | 831 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
832 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
833 r_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
834 i_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
835 } |
1 | 836 } |
5086 | 837 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 838 { |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
839 r_fmt = float_format (r_fw, ld); |
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
840 i_fmt = float_format (i_fw, ld); |
3611 | 841 } |
1 | 842 else |
843 { | |
3608 | 844 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
845 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 846 } |
847 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
848 return float_display_format (r_fmt, i_fmt); |
1 | 849 } |
850 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
851 template <typename T> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
852 float_display_format |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
853 make_complex_scalar_format (const std::complex<T>& c) |
1658 | 854 { |
855 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
856 return float_display_format (); |
1658 | 857 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
858 T rp = c.real (); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
859 T ip = c.imag (); |
1658 | 860 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
861 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
|
862 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
863 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
|
864 && octave::math::x_nint (ip) == ip); |
1658 | 865 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
866 T r_abs = (rp < 0 ? -rp : rp); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
867 T i_abs = (ip < 0 ? -ip : ip); |
1658 | 868 |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
869 int r_x = (! octave::math::isfinite (rp) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
870 || r_abs == 0) ? 0 : num_digits (r_abs); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
871 |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
872 int i_x = (! octave::math::isfinite (ip) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
873 || i_abs == 0) ? 0 : num_digits (i_abs); |
1658 | 874 |
875 int x_max, x_min; | |
876 | |
877 if (r_x > i_x) | |
878 { | |
879 x_max = r_x; | |
880 x_min = i_x; | |
881 } | |
882 else | |
883 { | |
884 x_max = i_x; | |
885 x_min = r_x; | |
886 } | |
887 | |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
888 return make_complex_format<T> (x_max, x_min, r_x, inf_or_nan, int_only); |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
889 } |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
890 |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
891 template <> |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
892 float_display_format |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
893 make_format (const std::complex<double>& c) |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
894 { |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
895 return make_complex_scalar_format (c); |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
896 } |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
897 |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
898 template <> |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
899 float_display_format |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
900 make_format (const std::complex<float>& fc) |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
901 { |
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
902 return make_complex_scalar_format (fc); |
1 | 903 } |
904 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
905 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
906 static inline float_display_format |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
907 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
|
908 int r_x_min, bool inf_or_nan, |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
909 int int_or_inf_or_nan) |
1 | 910 { |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
911 T scale = ((x_max == 0 || int_or_inf_or_nan) |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
912 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
913 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
914 float_format r_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
915 float_format i_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
916 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
917 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 918 |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
919 int i_fw = 0, r_fw = 0, ld = 0, rd = 0; |
1 | 920 |
6788 | 921 if (rat_format) |
922 { | |
923 i_fw = 9; | |
924 r_fw = 9; | |
925 rd = 0; | |
926 } | |
927 else if (bank_format) | |
1 | 928 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
929 int digits = (r_x_max > r_x_min ? r_x_max : r_x_min); |
1 | 930 i_fw = 0; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
931 r_fw = (digits <= 0 ? 5 : digits + 4); |
1 | 932 rd = 2; |
933 } | |
1282 | 934 else if (hex_format) |
935 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
936 r_fw = 2 * sizeof (T); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
937 i_fw = 2 * sizeof (T); |
1282 | 938 rd = 0; |
939 } | |
1309 | 940 else if (bit_format) |
941 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
942 r_fw = 8 * sizeof (T); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
943 i_fw = 8 * sizeof (T); |
1309 | 944 rd = 0; |
945 } | |
4509 | 946 else if (Vfixed_point_format && ! print_g) |
3268 | 947 { |
27453
05f84e5cb08a
Display correct number of digits with "format long" and fixed_point_format (bug #56938).
Rik <rik@octave.org>
parents:
27451
diff
changeset
|
948 rd = prec - 1; |
5945 | 949 i_fw = rd + 1; |
27453
05f84e5cb08a
Display correct number of digits with "format long" and fixed_point_format (bug #56938).
Rik <rik@octave.org>
parents:
27451
diff
changeset
|
950 r_fw = i_fw + 2; |
5945 | 951 if (inf_or_nan && i_fw < 3) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
952 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
953 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
954 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
955 } |
3268 | 956 } |
1715 | 957 else if (int_or_inf_or_nan) |
1 | 958 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
959 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
|
960 i_fw = (digits <= 0 ? 1 : digits); |
5945 | 961 r_fw = i_fw + 1; |
962 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
963 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
964 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
965 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
966 } |
3682 | 967 rd = r_fw; |
1 | 968 } |
969 else | |
970 { | |
971 int ld_max, rd_max; | |
972 if (x_max > 0) | |
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 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
975 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
|
976 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
977 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
978 else if (x_max < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
979 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
980 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
981 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
|
982 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
983 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
984 else |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
985 { |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
986 ld_max = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
987 rd_max = (prec > 1 ? prec - 1 : prec); |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
988 x_max = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
989 } |
1 | 990 |
991 int ld_min, rd_min; | |
992 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
993 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
994 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
995 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
|
996 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
997 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
998 else if (x_min < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
999 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1000 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1001 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
|
1002 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1003 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1004 else |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1005 { |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1006 ld_min = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1007 rd_min = (prec > 1 ? prec - 1 : prec); |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1008 x_min = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1009 } |
1 | 1010 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1011 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
|
1012 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 1013 |
5945 | 1014 i_fw = ld + 1 + rd; |
1015 r_fw = i_fw + 1; | |
1016 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1017 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1018 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1019 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1020 } |
1 | 1021 } |
1022 | |
6788 | 1023 if (! (rat_format || bank_format || hex_format || bit_format) |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
1024 && (print_e || print_eng || print_g |
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
1025 || (! Vfixed_point_format |
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
1026 && (ld + rd > pr_output_traits<T>::digits10 |
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
1027 || r_fw > pr_output_traits<T>::max_field_width |
27466
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
1028 || i_fw > pr_output_traits<T>::max_field_width |
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
1029 || ld + rd > (1.5 * prec))))) |
1 | 1030 { |
4509 | 1031 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1032 { |
27439
251056aeba5d
Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents:
27434
diff
changeset
|
1033 int width = prec + 6; |
27429
e0134184c1fd
Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
1034 r_fmt = float_format (width, prec); |
e0134184c1fd
Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
1035 i_fmt = float_format (width, prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1036 } |
4509 | 1037 else |
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 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1040 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
|
1041 ex++; |
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 if (print_eng) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1044 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1045 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
|
1046 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
|
1047 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
|
1048 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1049 i_fw = 5; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1050 r_fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1051 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1052 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
|
1053 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
|
1054 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1055 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1056 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1057 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
|
1058 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
|
1059 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
|
1060 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1061 i_fw = 3; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1062 r_fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1063 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1064 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
|
1065 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
|
1066 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1067 } |
3608 | 1068 |
1 | 1069 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1070 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1071 r_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1072 i_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1073 } |
1 | 1074 } |
5086 | 1075 else if (! bank_format && int_or_inf_or_nan) |
3611 | 1076 { |
1077 r_fmt = float_format (r_fw, rd); | |
1078 i_fmt = float_format (i_fw, rd); | |
1079 } | |
1 | 1080 else |
1081 { | |
3608 | 1082 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
1083 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 1084 } |
1085 | |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1086 return float_display_format (scale, r_fmt, i_fmt); |
1 | 1087 } |
1088 | |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1089 template <typename CMT> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1090 static inline float_display_format |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1091 make_complex_matrix_format (const CMT& cm) |
1658 | 1092 { |
1093 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1094 return float_display_format (); |
1658 | 1095 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1096 typedef typename CMT::real_matrix_type RMT; |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1097 typedef typename CMT::real_elt_type ELT_T; |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1098 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1099 RMT rp = real (cm); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1100 RMT ip = imag (cm); |
1658 | 1101 |
2387 | 1102 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658 | 1103 |
2387 | 1104 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
|
1105 && ip.all_elements_are_int_or_inf_or_nan ()); |
1658 | 1106 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1107 RMT r_m_abs = rp.abs (); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1108 ELT_T r_max_abs = pr_max_internal (r_m_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1109 ELT_T r_min_abs = pr_min_internal (r_m_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1110 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1111 RMT i_m_abs = ip.abs (); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1112 ELT_T i_max_abs = pr_max_internal (i_m_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1113 ELT_T i_min_abs = pr_min_internal (i_m_abs); |
1658 | 1114 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1115 int r_x_max = (r_max_abs == 0 ? 0 : num_digits (r_max_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1116 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1117 int r_x_min = (r_min_abs == 0 ? 0 : num_digits (r_min_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1118 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1119 int i_x_max = (i_max_abs == 0 ? 0 : num_digits (i_max_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1120 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1121 int i_x_min = (i_min_abs == 0 ? 0 : num_digits (i_min_abs)); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1122 |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1123 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
|
1124 int x_min = (r_x_min > i_x_min ? r_x_min : i_x_min); |
1658 | 1125 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1126 return make_complex_matrix_format<ELT_T> (x_max, x_min, r_x_max, r_x_min, |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1127 inf_or_nan, int_or_inf_or_nan); |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1128 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1129 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1130 template <> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1131 float_display_format |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1132 make_format (const ComplexMatrix& cm) |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1133 { |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1134 return make_complex_matrix_format (cm); |
1658 | 1135 } |
1136 | |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1137 template <> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1138 float_display_format |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1139 make_format (const FloatComplexMatrix& cm) |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1140 { |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1141 return make_complex_matrix_format (cm); |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1142 } |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1143 |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1144 template <> |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1145 float_display_format |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1146 make_format (const boolNDArray&) |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1147 { |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1148 return float_display_format (float_format (1, 1)); |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1149 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1150 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1151 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1152 static inline float_display_format |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1153 make_range_format (int x_max, int x_min, int all_ints) |
1 | 1154 { |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1155 double scale = ((x_max == 0 || all_ints) |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1156 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1157 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1158 float_format fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1159 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1160 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 1161 |
24789
a4d4ec566fd7
improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24788
diff
changeset
|
1162 int fw = 0, ld = 0, rd = 0; |
1 | 1163 |
6788 | 1164 if (rat_format) |
1165 { | |
1166 fw = 9; | |
1167 rd = 0; | |
1168 } | |
1169 else if (bank_format) | |
1 | 1170 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1171 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
|
1172 fw = (digits < 0 ? 5 : digits + 4); |
1 | 1173 rd = 2; |
1174 } | |
1282 | 1175 else if (hex_format) |
1176 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1177 fw = 2 * sizeof (T); |
1282 | 1178 rd = 0; |
1179 } | |
1309 | 1180 else if (bit_format) |
1181 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1182 fw = 8 * sizeof (T); |
1309 | 1183 rd = 0; |
1184 } | |
1658 | 1185 else if (all_ints) |
1 | 1186 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1187 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
|
1188 fw = digits + 1; |
3682 | 1189 rd = fw; |
1 | 1190 } |
4509 | 1191 else if (Vfixed_point_format && ! print_g) |
3105 | 1192 { |
27453
05f84e5cb08a
Display correct number of digits with "format long" and fixed_point_format (bug #56938).
Rik <rik@octave.org>
parents:
27451
diff
changeset
|
1193 rd = prec - 1; |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1194 fw = rd + 3; |
3105 | 1195 } |
1 | 1196 else |
1197 { | |
1198 int ld_max, rd_max; | |
1199 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1201 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1202 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
|
1203 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1204 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1205 else if (x_max < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1206 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1207 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1208 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
|
1209 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1210 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1211 else |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1212 { |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1213 ld_max = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1214 rd_max = (prec > 1 ? prec - 1 : prec); |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1215 x_max = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1216 } |
1 | 1217 |
1218 int ld_min, rd_min; | |
1219 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1220 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1221 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1222 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
|
1223 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1224 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1225 else if (x_min < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1226 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1227 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1228 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
|
1229 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1230 } |
27451
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1231 else |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1232 { |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1233 ld_min = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1234 rd_min = (prec > 1 ? prec - 1 : prec); |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1235 x_min = 1; |
ce0399fa017a
Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents:
27439
diff
changeset
|
1236 } |
1 | 1237 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1238 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
|
1239 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 1240 |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1241 fw = ld + rd + 3; |
1 | 1242 } |
1243 | |
6788 | 1244 if (! (rat_format || bank_format || hex_format || bit_format) |
24785
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
1245 && (print_e || print_eng || print_g |
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
1246 || (! Vfixed_point_format |
504869574c89
restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents:
24784
diff
changeset
|
1247 && (ld + rd > pr_output_traits<T>::digits10 |
27466
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
1248 || fw > pr_output_traits<T>::max_field_width |
6e8dac65d405
Switch to scientific notation for format short when values are large or small (bug #56971).
Rik <rik@octave.org>
parents:
27459
diff
changeset
|
1249 || ld + rd > (1.5 * prec))))) |
1 | 1250 { |
4509 | 1251 if (print_g) |
27439
251056aeba5d
Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents:
27434
diff
changeset
|
1252 fmt = float_format (prec+6, prec); |
4509 | 1253 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1254 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1255 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1256 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
|
1257 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1258 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1259 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1260 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1261 fw = 5 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1262 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
|
1263 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1264 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1265 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1266 fw = 3 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1267 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
|
1268 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1269 } |
3608 | 1270 |
1 | 1271 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1272 fmt.uppercase (); |
1 | 1273 } |
5086 | 1274 else if (! bank_format && all_ints) |
3611 | 1275 fmt = float_format (fw, rd); |
1 | 1276 else |
3608 | 1277 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 1278 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1279 return float_display_format (scale, fmt); |
1 | 1280 } |
1281 | |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1282 template <> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1283 float_display_format |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1284 make_format (const Range& r) |
1658 | 1285 { |
1286 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1287 return float_display_format (); |
1658 | 1288 |
1289 double r_min = r.base (); | |
1290 double r_max = r.limit (); | |
1291 | |
1292 if (r_max < r_min) | |
1293 { | |
1294 double tmp = r_max; | |
1295 r_max = r_min; | |
1296 r_min = tmp; | |
1297 } | |
1298 | |
2387 | 1299 bool all_ints = r.all_elements_are_ints (); |
1658 | 1300 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1301 double max_abs = (r_max < 0 ? -r_max : r_max); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1302 double min_abs = (r_min < 0 ? -r_min : r_min); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1303 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1304 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1305 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1306 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1307 |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1308 return make_range_format<double> (x_max, x_min, all_ints); |
1 | 1309 } |
1310 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1311 template <typename T> |
1282 | 1312 union equiv |
1313 { | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1314 T val; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1315 unsigned char i[sizeof (T)]; |
1282 | 1316 }; |
1317 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1318 #define PRINT_CHAR_BITS(os, c) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1319 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1320 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1321 unsigned char ctmp = c; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1322 char stmp[9]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1323 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1324 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1325 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1326 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1327 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1328 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1329 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1330 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1331 stmp[8] = '\0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1332 os << stmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1333 } \ |
1309 | 1334 while (0) |
1335 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1336 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1337 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1338 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1339 unsigned char ctmp = c; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1340 char stmp[9]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1341 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1342 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1343 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1344 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1345 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1346 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1347 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1348 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1349 stmp[8] = '\0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1350 os << stmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1351 } \ |
1309 | 1352 while (0) |
1353 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1354 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1355 static inline void |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1356 pr_any_float (std::ostream& os, const float_format& fmt, T val) |
1 | 1357 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1358 // 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
|
1359 // for hex and bit formats. |
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 // {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
|
1362 // {bit,hex}_format == 2: print native |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1363 |
27183
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
1364 int fw = fmt.width (); |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1365 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1366 if (hex_format) |
1 | 1367 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1368 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
|
1369 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1370 equiv<T> tmp; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1371 tmp.val = val; |
24667
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 // 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
|
1374 |
27459
36b610122086
Correctly display integer types with format hex (bug #56966).
Rik <rik@octave.org>
parents:
27458
diff
changeset
|
1375 // FIXME: Will bad things happen if we are interrupted before resetting |
36b610122086
Correctly display integer types with format hex (bug #56966).
Rik <rik@octave.org>
parents:
27458
diff
changeset
|
1376 // the format flags and fill character? |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1377 |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27183
diff
changeset
|
1378 octave::mach_info::float_format flt_fmt |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27183
diff
changeset
|
1379 = octave::mach_info::native_float_format (); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1380 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1381 os.fill ('0'); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1382 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
|
1383 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1384 if (hex_format > 1 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1385 || 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
|
1386 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1387 for (size_t i = 0; i < sizeof (T); i++) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1388 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
|
1389 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1390 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1391 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1392 for (int i = sizeof (T) - 1; i >= 0; i--) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1393 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
|
1394 } |
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 else if (bit_format) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1397 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1398 equiv<T> tmp; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1399 tmp.val = val; |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1400 |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27183
diff
changeset
|
1401 octave::mach_info::float_format flt_fmt |
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27183
diff
changeset
|
1402 = octave::mach_info::native_float_format (); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1403 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1404 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
|
1405 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1406 for (size_t i = 0; i < sizeof (T); i++) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1407 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
|
1408 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1409 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1410 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1411 if (bit_format > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1412 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1413 for (size_t i = 0; i < sizeof (T); i++) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1414 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
|
1415 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1416 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1417 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1418 for (int i = sizeof (T) - 1; i >= 0; i--) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1419 PRINT_CHAR_BITS (os, tmp.i[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1420 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1421 } |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1422 } |
27433
fc7504df6a12
Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents:
27430
diff
changeset
|
1423 else if (val == 0) |
fc7504df6a12
Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents:
27430
diff
changeset
|
1424 { |
fc7504df6a12
Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents:
27430
diff
changeset
|
1425 octave::preserve_stream_state stream_state (os); |
fc7504df6a12
Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents:
27430
diff
changeset
|
1426 |
fc7504df6a12
Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents:
27430
diff
changeset
|
1427 if (fw > 0) |
fc7504df6a12
Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents:
27430
diff
changeset
|
1428 os << std::setw (fw) << "0"; |
fc7504df6a12
Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents:
27430
diff
changeset
|
1429 else |
fc7504df6a12
Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents:
27430
diff
changeset
|
1430 os << "0"; |
fc7504df6a12
Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents:
27430
diff
changeset
|
1431 } |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1432 else if (octave::math::isna (val)) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1433 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1434 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
|
1435 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1436 if (fw > 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1437 os << std::setw (fw) << "NA"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1438 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1439 os << "NA"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1440 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1441 else if (rat_format) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1442 os << pr_rational_float<T> (fmt, val); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1443 else if (octave::math::isinf (val)) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1444 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1445 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
|
1446 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1447 const char *s; |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1448 if (val < 0) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1449 s = "-Inf"; |
1 | 1450 else |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1451 s = "Inf"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1452 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1453 if (fw > 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1454 os << std::setw (fw) << s; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1455 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1456 os << s; |
1 | 1457 } |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1458 else if (octave::math::isnan (val)) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1459 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1460 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
|
1461 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1462 if (fw > 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1463 os << std::setw (fw) << "NaN"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1464 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1465 os << "NaN"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1466 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1467 else if (print_eng) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1468 os << pr_engineering_float<T> (fmt, val); |
529 | 1469 else |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1470 os << pr_formatted_float<T> (fmt, val); |
1 | 1471 } |
1472 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1473 template <typename T> |
1 | 1474 static inline void |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1475 pr_float (std::ostream& os, const float_display_format& fmt, T val) |
1 | 1476 { |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1477 double scale = fmt.scale_factor (); |
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1478 |
27434
57f5c5768eb3
Disallow exponential format in combination with fixed_point_format.
Rik <rik@octave.org>
parents:
27433
diff
changeset
|
1479 if (Vfixed_point_format && ! (print_g || print_e) && scale != 1) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1480 val /= scale; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1481 |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1482 pr_any_float (os, fmt.real_format (), val); |
1 | 1483 } |
1484 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1485 template <typename T> |
1 | 1486 static inline void |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1487 pr_imag_float (std::ostream& os, const float_display_format& fmt, T val) |
1 | 1488 { |
27454
43ece0b8318b
Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents:
27453
diff
changeset
|
1489 double scale = fmt.scale_factor (); |
43ece0b8318b
Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents:
27453
diff
changeset
|
1490 |
43ece0b8318b
Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents:
27453
diff
changeset
|
1491 if (Vfixed_point_format && ! (print_g || print_e) && scale != 1) |
43ece0b8318b
Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents:
27453
diff
changeset
|
1492 val /= scale; |
43ece0b8318b
Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents:
27453
diff
changeset
|
1493 |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1494 pr_any_float (os, fmt.imag_format (), val); |
1 | 1495 } |
1496 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1497 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1498 static inline void |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1499 pr_float (std::ostream& os, const float_display_format& fmt, |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1500 const std::complex<T>& cval) |
1 | 1501 { |
27454
43ece0b8318b
Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents:
27453
diff
changeset
|
1502 T r = cval.real (); |
3608 | 1503 |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1504 pr_float (os, fmt, r); |
3608 | 1505 |
1 | 1506 if (! bank_format) |
1507 { | |
27454
43ece0b8318b
Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents:
27453
diff
changeset
|
1508 T i = cval.imag (); |
4349 | 1509 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
|
1510 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1511 os << " - "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1512 i = -i; |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1513 pr_imag_float (os, fmt, i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1514 } |
1 | 1515 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1516 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1517 if (hex_format || bit_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1518 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1519 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1520 os << " + "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1521 |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1522 pr_imag_float (os, fmt, i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1523 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1524 os << 'i'; |
1 | 1525 } |
1526 } | |
1527 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1528 static inline void |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1529 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
|
1530 bool pr_as_read_syntax) |
626 | 1531 { |
1532 assert (nr == 0 || nc == 0); | |
1533 | |
1534 if (pr_as_read_syntax) | |
1535 { | |
1536 if (nr == 0 && nc == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1537 os << "[]"; |
626 | 1538 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1539 os << "zeros (" << nr << ", " << nc << ')'; |
626 | 1540 } |
1541 else | |
1542 { | |
1543 os << "[]"; | |
4559 | 1544 |
2165 | 1545 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
|
1546 os << '(' << nr << 'x' << nc << ')'; |
626 | 1547 } |
1548 } | |
1549 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1550 static inline void |
4559 | 1551 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
|
1552 bool pr_as_read_syntax) |
4559 | 1553 { |
1554 assert (dims.any_zero ()); | |
1555 | |
1556 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
|
1557 os << "zeros (" << dims.str (',') << ')'; |
4559 | 1558 else |
1559 { | |
1560 os << "[]"; | |
1561 | |
1562 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
|
1563 os << '(' << dims.str () << ')'; |
4559 | 1564 } |
1565 } | |
1566 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1567 static inline void |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1568 pr_scale_header (std::ostream& os, double scale) |
3105 | 1569 { |
27434
57f5c5768eb3
Disallow exponential format in combination with fixed_point_format.
Rik <rik@octave.org>
parents:
27433
diff
changeset
|
1570 if (Vfixed_point_format && ! (print_g || print_e) && scale != 1) |
3105 | 1571 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
1572 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
|
1573 |
3568 | 1574 os << " " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1575 << std::setw (8) << std::setprecision (1) |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21583
diff
changeset
|
1576 << 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
|
1577 << scale |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
1578 << "*\n"; |
3105 | 1579 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1580 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1581 os << "\n"; |
3105 | 1582 } |
1583 } | |
1584 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1585 static inline void |
5275 | 1586 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
|
1587 octave_idx_type lim, octave_idx_type col, int extra_indent) |
1186 | 1588 { |
2165 | 1589 if (total_width > max_width && Vsplit_long_rows) |
1186 | 1590 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
1591 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
|
1592 |
4833 | 1593 if (col != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1594 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1595 if (Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1596 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1597 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1598 os << "\n\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1599 } |
1186 | 1600 |
5275 | 1601 octave_idx_type num_cols = lim - col; |
1186 | 1602 |
3548 | 1603 os << std::setw (extra_indent) << ""; |
1972 | 1604 |
1186 | 1605 if (num_cols == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1606 os << " Column " << col + 1 << ":\n"; |
1186 | 1607 else if (num_cols == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1608 os << " Columns " << col + 1 << " and " << lim << ":\n"; |
1186 | 1609 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1610 os << " Columns " << col + 1 << " through " << lim << ":\n"; |
2915 | 1611 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1612 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1613 os << "\n"; |
1186 | 1614 } |
1615 } | |
1616 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
1617 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1618 static inline void |
5030 | 1619 pr_plus_format (std::ostream& os, const T& val) |
3248 | 1620 { |
5030 | 1621 if (val > T (0)) |
4632 | 1622 os << plus_format_chars[0]; |
5030 | 1623 else if (val < T (0)) |
4632 | 1624 os << plus_format_chars[1]; |
3248 | 1625 else |
4632 | 1626 os << plus_format_chars[2]; |
3248 | 1627 } |
1628 | |
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
|
1629 // 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
|
1630 // |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1631 // 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
|
1632 // |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1633 // 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
|
1634 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1635 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1636 static inline T |
24747
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1637 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
|
1638 { |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1639 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
|
1640 } |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1641 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1642 #define INSTANTIATE_ABS(T) \ |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1643 template T abs (T) |
24747
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1644 |
25569
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1645 INSTANTIATE_ABS(int8_t); |
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1646 INSTANTIATE_ABS(int16_t); |
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1647 INSTANTIATE_ABS(int32_t); |
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1648 INSTANTIATE_ABS(int64_t); |
24747
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1649 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1650 #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
|
1651 template <> \ |
25569
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1652 inline T \ |
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1653 abs (T x) \ |
24747
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1654 { \ |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1655 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
|
1656 } |
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 |
25569
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1658 SPECIALIZE_UABS(uint8_t) |
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1659 SPECIALIZE_UABS(uint16_t) |
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1660 SPECIALIZE_UABS(uint32_t) |
e8961d677661
build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents:
25108
diff
changeset
|
1661 SPECIALIZE_UABS(uint64_t) |
24747
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1662 |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1663 #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
|
1664 template <> \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1665 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
|
1666 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
|
1667 { \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1668 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
|
1669 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
|
1670 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1671 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
|
1672 { \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1673 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
|
1674 = static_cast<int> \ |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1675 (std::floor (log10 (double (abs (nda(i).value ()))) + 1)); \ |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1676 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1677 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
|
1678 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
|
1679 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1680 if (! isneg) \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1681 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
|
1682 } \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1683 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1684 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
|
1685 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1686 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1687 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
|
1688 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
|
1689 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
|
1690 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
|
1691 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
|
1692 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
|
1693 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
|
1694 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
|
1695 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1696 #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
|
1697 template <> \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1698 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
|
1699 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
|
1700 { \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1701 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
|
1702 int digits \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1703 = static_cast<int> \ |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1704 (std::floor (log10 (double (abs (val.value ()))) + 1)); \ |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1705 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1706 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
|
1707 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1708 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
|
1709 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1710 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1711 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
|
1712 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
|
1713 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
|
1714 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
|
1715 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
|
1716 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
|
1717 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
|
1718 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
|
1719 |
1 | 1720 void |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1721 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
|
1722 bool d, bool pr_as_read_syntax) |
1 | 1723 { |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1724 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
|
1725 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1726 |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1727 void |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1728 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
|
1729 { |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1730 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
|
1731 } |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1732 |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1733 void |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1734 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
|
1735 char, bool) |
1 | 1736 { |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1737 panic_impossible (); |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1738 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1739 |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1740 void |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1741 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
|
1742 double d, bool pr_as_read_syntax) |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1743 { |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1744 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
|
1745 os << d; |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1746 else if (plus_format) |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1747 pr_plus_format (os, d); |
1 | 1748 else |
1749 { | |
1750 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1751 os << d; |
1 | 1752 else |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1753 pr_float (os, fmt, d); |
1 | 1754 } |
1755 } | |
1756 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1757 void |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1758 octave_print_internal (std::ostream& os, const float_display_format& fmt, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1759 float d, bool pr_as_read_syntax) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1760 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1761 if (pr_as_read_syntax) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1762 os << d; |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1763 else if (plus_format) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1764 pr_plus_format (os, d); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1765 else |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1766 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1767 if (free_format) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1768 os << d; |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1769 else |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1770 pr_float (os, fmt, d); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1771 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1772 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1773 |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1774 template <typename MT> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1775 static inline void |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1776 octave_print_free (std::ostream& os, const MT& m, bool pr_as_read_syntax) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1777 { |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1778 octave_idx_type nr = m.rows (); |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1779 octave_idx_type nc = m.columns (); |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1780 |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1781 if (pr_as_read_syntax) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1782 os << "[\n"; |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1783 |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1784 for (octave_idx_type i = 0; i < nr; i++) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1785 { |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1786 for (octave_idx_type j = 0; j < nc; j++) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1787 os << ' ' << m.elem(i,j); |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1788 |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1789 if (i < nr - 1) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1790 os << "\n"; |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1791 } |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1792 |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1793 if (pr_as_read_syntax) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1794 os << ']'; |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1795 } |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1796 |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1797 template <typename MT> |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1798 static inline void |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1799 pr_plus_format_matrix (std::ostream& os, const MT& m) |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1800 { |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1801 octave_idx_type nr = m.rows (); |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1802 octave_idx_type nc = m.columns (); |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1803 |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1804 for (octave_idx_type i = 0; i < nr; i++) |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1805 { |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1806 for (octave_idx_type j = 0; j < nc; j++) |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1807 { |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1808 octave_quit (); |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1809 |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1810 pr_plus_format (os, m(i,j)); |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1811 } |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1812 |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1813 if (i < nr - 1) |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1814 os << "\n"; |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1815 } |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1816 } |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1817 |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1818 static inline int |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1819 get_column_width (const float_display_format& fmt) |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1820 { |
27183
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
1821 int r_fw = fmt.real_format().width (); |
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
1822 int i_fw = fmt.imag_format().width (); |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1823 |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1824 int retval = r_fw + i_fw + 2; |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1825 |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1826 if (i_fw && ! (rat_format || bank_format || hex_format || bit_format)) |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1827 retval += 5; |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1828 |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1829 return retval; |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1830 } |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1831 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1832 template <typename MT> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1833 static void |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1834 octave_print_matrix_internal (std::ostream& os, const MT& m, |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1835 bool pr_as_read_syntax, int extra_indent) |
1 | 1836 { |
5275 | 1837 octave_idx_type nr = m.rows (); |
1838 octave_idx_type nc = m.columns (); | |
1 | 1839 |
2408 | 1840 if (nr == 0 || nc == 0) |
626 | 1841 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1842 else if (plus_format && ! pr_as_read_syntax) | |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1843 pr_plus_format_matrix (os, m); |
1 | 1844 else |
1845 { | |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1846 float_display_format fmt = make_format (m); |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1847 int column_width = get_column_width (fmt); |
5275 | 1848 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
|
1849 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
1 | 1850 |
626 | 1851 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1852 max_width -= 4; |
1972 | 1853 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1854 max_width -= extra_indent; |
1972 | 1855 |
1856 if (max_width < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1857 max_width = 0; |
626 | 1858 |
1 | 1859 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1860 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1861 octave_print_free (os, m, pr_as_read_syntax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1862 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1863 } |
1 | 1864 |
5275 | 1865 octave_idx_type inc = nc; |
2165 | 1866 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
|
1867 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1868 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1869 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1870 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1871 } |
1 | 1872 |
626 | 1873 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1874 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1875 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
|
1876 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1877 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1878 while (col < nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1879 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1880 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
|
1881 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1882 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
|
1883 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1884 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1885 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1886 if (i == 0 && j == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1887 os << "[ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1888 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1889 { |
26501
cfe28edab48b
pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
1890 if (j > col) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1891 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1892 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1893 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1894 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1895 |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
1896 pr_float (os, fmt, m(i,j)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1897 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1898 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1899 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1900 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1901 if (col >= nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1902 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1903 if (i == nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1904 os << " ]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1905 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1906 os << ";\n"; |
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 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1909 os << " ...\n"; |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1912 } |
626 | 1913 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1914 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
1915 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
|
1916 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1917 pr_scale_header (os, fmt.scale_factor ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1918 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1919 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
|
1920 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
1921 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
|
1922 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1923 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
|
1924 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1925 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1926 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
|
1927 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1928 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1929 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1930 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
|
1931 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1932 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1933 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1934 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1935 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1936 pr_float (os, fmt, m(i,j)); |
10315
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1939 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1940 os << "\n"; |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1943 } |
1 | 1944 } |
1945 } | |
1946 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1947 template <typename DMT> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1948 static void |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1949 octave_print_diag_matrix_internal (std::ostream& os, const DMT& m, |
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1950 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1951 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1952 octave_idx_type nr = m.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1953 octave_idx_type nc = m.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1954 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1955 if (nr == 0 || nc == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1956 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
|
1957 else if (plus_format && ! pr_as_read_syntax) |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1958 pr_plus_format_matrix (os, m); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1959 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1960 { |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
1961 float_display_format fmt |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
1962 = make_format (typename DMT::full_matrix_type (m.diag ())); |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
1963 int column_width = get_column_width (fmt); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1964 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
|
1965 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
|
1966 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1967 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1968 max_width -= 4; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1969 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1970 max_width -= extra_indent; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1971 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1972 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1973 max_width = 0; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1974 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1975 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1976 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1977 octave_print_free (os, m, pr_as_read_syntax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1978 return; |
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 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1982 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
|
1983 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1984 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1985 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1986 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1987 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1988 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1989 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1990 { |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1991 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1992 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1993 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1994 while (col < nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1995 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
1996 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
|
1997 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1998 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1999 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2000 octave_quit (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2001 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2002 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2003 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2004 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2005 { |
26501
cfe28edab48b
pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2006 if (j > col) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2007 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2008 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2009 os << " "; |
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 |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2012 pr_float (os, fmt, m(j,j)); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2013 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2014 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2015 col += inc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2016 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2017 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2018 os << " ]"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2019 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2020 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2021 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2022 os << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2023 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2024 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2025 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2026 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
|
2027 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2028 os << "Diagonal Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2029 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2030 os << "\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2031 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
2032 pr_scale_header (os, fmt.scale_factor ()); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2033 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21748
diff
changeset
|
2034 // kluge. Get the true width of a number. |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2035 int zero_fw; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2036 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2037 std::ostringstream tmp_oss; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2038 typename DMT::element_type zero = 0; |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
2039 pr_float (tmp_oss, fmt, zero); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2040 zero_fw = tmp_oss.str ().length (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2041 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2042 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2043 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
|
2044 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2045 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
|
2046 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2047 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
|
2048 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2049 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2050 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
|
2051 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2052 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2053 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2054 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
|
2055 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2056 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2057 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2058 os << " "; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2059 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2060 if (i == j) |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
2061 pr_float (os, fmt, m(i,j)); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2062 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2063 os << std::setw (zero_fw) << '0'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2064 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2065 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2066 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2067 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2068 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2069 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2070 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2071 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2072 } |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2073 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2074 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
|
2075 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
|
2076 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
|
2077 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2078 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
2079 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
|
2080 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
|
2081 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2082 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2083 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2084 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
|
2085 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2086 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
|
2087 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2088 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
|
2089 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2090 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
|
2091 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2092 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
|
2093 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
|
2094 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2095 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
|
2096 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
|
2097 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2098 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
|
2099 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2100 octave_quit (); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2101 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2102 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
|
2103 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2104 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
|
2105 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2106 nm += "(:,:,"; |
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 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
|
2109 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2110 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
|
2111 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2112 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
|
2113 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2114 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
|
2115 buf << ','; |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2116 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2117 buf << ')'; |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2118 } |
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 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
|
2121 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2122 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2123 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
|
2124 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2125 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
|
2126 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
|
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 (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
|
2129 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
|
2130 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2131 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
|
2132 = 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
|
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 (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
|
2135 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2136 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
|
2137 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2138 else |
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 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
|
2141 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
|
2142 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2143 |
26501
cfe28edab48b
pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2144 NDA_T::increment_index (ra_idx, dims, 2); |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2145 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2146 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2147 } |
4532 | 2148 |
4513 | 2149 void |
2150 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
|
2151 bool pr_as_read_syntax, int extra_indent) |
4513 | 2152 { |
2153 switch (nda.ndims ()) | |
2154 { | |
2155 case 1: | |
2156 case 2: | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19318
diff
changeset
|
2157 octave_print_internal (os, Matrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2158 pr_as_read_syntax, extra_indent); |
4513 | 2159 break; |
2160 | |
2161 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2162 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax); |
4513 | 2163 break; |
2164 } | |
2165 } | |
2166 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2167 void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2168 octave_print_internal (std::ostream& os, const FloatNDArray& nda, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2169 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2170 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2171 switch (nda.ndims ()) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2172 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2173 case 1: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2174 case 2: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2175 octave_print_internal (os, FloatMatrix (nda), |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2176 pr_as_read_syntax, extra_indent); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2177 break; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2178 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2179 default: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2180 print_nd_array <FloatNDArray, float, FloatMatrix> (os, nda, pr_as_read_syntax); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2181 break; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2182 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2183 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2184 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2185 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2186 static inline void |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2187 pr_plus_format (std::ostream& os, const std::complex<T>& c) |
3248 | 2188 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2189 T rp = c.real (); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2190 T ip = c.imag (); |
3248 | 2191 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2192 if (rp == 0) |
3248 | 2193 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2194 if (ip == 0) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2195 os << ' '; |
3248 | 2196 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2197 os << 'i'; |
3248 | 2198 } |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2199 else if (ip == 0) |
3608 | 2200 pr_plus_format (os, rp); |
3248 | 2201 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2202 os << 'c'; |
3248 | 2203 } |
2204 | |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2205 extern void |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2206 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
|
2207 const Complex& c, bool pr_as_read_syntax) |
1 | 2208 { |
17867
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2209 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
|
2210 os << c; |
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2211 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
|
2212 pr_plus_format (os, c); |
1 | 2213 else |
2214 { | |
2215 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2216 os << c; |
1 | 2217 else |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2218 pr_float (os, fmt, c); |
1 | 2219 } |
2220 } | |
2221 | |
2222 void | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2223 octave_print_internal (std::ostream& os, const float_display_format& fmt, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2224 const FloatComplex& c, bool pr_as_read_syntax) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2225 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2226 if (pr_as_read_syntax) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2227 os << c; |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2228 else if (plus_format) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2229 pr_plus_format (os, c); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2230 else |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2231 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2232 if (free_format) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2233 os << c; |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2234 else |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2235 pr_float (os, fmt, c); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2236 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2237 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2238 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2239 void |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2240 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
|
2241 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
|
2242 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2243 octave_idx_type nr = m.rows (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2244 octave_idx_type nc = m.columns (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2245 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2246 if (nr == 0 || nc == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2247 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
|
2248 else if (plus_format && ! pr_as_read_syntax) |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
2249 pr_plus_format_matrix (os, m); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2250 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2251 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2252 int fw = 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2253 int column_width = fw + 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2254 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
|
2255 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
|
2256 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2257 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2258 max_width -= 4; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2259 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2260 max_width -= extra_indent; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2261 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2262 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2263 max_width = 0; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2264 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2265 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2266 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2267 octave_print_free (os, m, pr_as_read_syntax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2268 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2269 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2270 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2271 octave_idx_type inc = nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2272 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
|
2273 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2274 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2275 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2276 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2277 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2278 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2279 if (pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2280 { |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18816
diff
changeset
|
2281 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
|
2282 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2283 os << "eye ("; |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18816
diff
changeset
|
2284 os << ":, "; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2285 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2286 octave_idx_type col = 0; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2287 while (col < nc) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2288 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2289 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
|
2290 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2291 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
|
2292 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2293 octave_quit (); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2294 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2295 if (j == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2296 os << "[ "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2297 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2298 { |
26501
cfe28edab48b
pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2299 if (j > col) |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2300 os << ", "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2301 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2302 os << " "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2303 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2304 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2305 os << pvec (j); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2306 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2307 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2308 col += inc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2309 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2310 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2311 os << " ]"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2312 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2313 os << " ...\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2314 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2315 os << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2316 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2317 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2318 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2319 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
|
2320 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2321 os << "Permutation Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2322 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2323 os << "\n"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2324 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2325 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
|
2326 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2327 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
|
2328 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2329 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
|
2330 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2331 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2332 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
|
2333 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2334 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2335 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2336 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
|
2337 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2338 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2339 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2340 os << " "; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2341 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2342 os << std::setw (fw) << m(i,j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2343 } |
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 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2346 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2347 } |
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 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2350 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2351 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2352 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2353 void |
4513 | 2354 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
|
2355 bool pr_as_read_syntax, int extra_indent) |
4513 | 2356 { |
2357 switch (nda.ndims ()) | |
2358 { | |
2359 case 1: | |
2360 case 2: | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19318
diff
changeset
|
2361 octave_print_internal (os, ComplexMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2362 pr_as_read_syntax, extra_indent); |
4513 | 2363 break; |
2364 | |
2365 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2366 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
|
2367 (os, nda, pr_as_read_syntax); |
4513 | 2368 break; |
2369 } | |
2370 } | |
2371 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2372 void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2373 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2374 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2375 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2376 switch (nda.ndims ()) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2377 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2378 case 1: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2379 case 2: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2380 octave_print_internal (os, FloatComplexMatrix (nda), |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2381 pr_as_read_syntax, extra_indent); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2382 break; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2383 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2384 default: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2385 print_nd_array <FloatComplexNDArray, FloatComplex, FloatComplexMatrix> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2386 (os, nda, pr_as_read_syntax); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2387 break; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2388 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2389 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2390 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2391 // 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
|
2392 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2393 void |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2394 octave_print_internal (std::ostream& os, const Matrix& m, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2395 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2396 { |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2397 octave_print_matrix_internal (os, m, pr_as_read_syntax, extra_indent); |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2398 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2399 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2400 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2401 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
|
2402 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
|
2403 { |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2404 octave_print_matrix_internal (os, m, pr_as_read_syntax, extra_indent); |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2405 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2406 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2407 void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2408 octave_print_internal (std::ostream& os, const DiagMatrix& m, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2409 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2410 { |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2411 octave_print_diag_matrix_internal (os, m, pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2412 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2413 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2414 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2415 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
|
2416 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
|
2417 { |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2418 octave_print_diag_matrix_internal (os, m, pr_as_read_syntax, extra_indent); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2419 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2420 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2421 void |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2422 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
|
2423 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
|
2424 { |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2425 octave_print_matrix_internal (os, cm, pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2426 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2427 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2428 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2429 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
|
2430 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
|
2431 { |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2432 octave_print_matrix_internal (os, cm, pr_as_read_syntax, extra_indent); |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2433 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2434 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2435 void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2436 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2437 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2438 { |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2439 octave_print_diag_matrix_internal (os, cm, pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2440 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2441 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2442 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2443 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
|
2444 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2445 { |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2446 octave_print_diag_matrix_internal (os, cm, pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2447 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2448 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2449 void |
3523 | 2450 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
|
2451 bool pr_as_read_syntax, int extra_indent) |
1 | 2452 { |
626 | 2453 double base = r.base (); |
1 | 2454 double increment = r.inc (); |
626 | 2455 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
|
2456 octave_idx_type num_elem = r.numel (); |
1 | 2457 |
626 | 2458 if (plus_format && ! pr_as_read_syntax) |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
2459 pr_plus_format_matrix (os, r); |
1 | 2460 else |
2461 { | |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
2462 float_display_format fmt = make_format (r); |
1 | 2463 |
626 | 2464 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2465 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2466 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2467 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2468 os << base << " : "; |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2469 if (increment != 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2470 os << increment << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2471 os << limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2472 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2473 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2474 { |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
2475 pr_float (os, fmt, base); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2476 os << " : "; |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2477 if (increment != 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2478 { |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
2479 pr_float (os, fmt, increment); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2480 os << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2481 } |
24786
0aeef407b04e
don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24785
diff
changeset
|
2482 pr_float (os, fmt, limit); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2483 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2484 } |
626 | 2485 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2486 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2487 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
|
2488 |
24788
6f04028d5d86
use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents:
24787
diff
changeset
|
2489 int column_width = get_column_width (fmt); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2490 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
|
2491 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
|
2492 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2493 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2494 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2495 os << ' '; |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2496 for (octave_idx_type i = 0; i < num_elem; i++) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2497 os << ' ' << r.elem(i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2498 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2499 } |
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 octave_idx_type inc = num_elem; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2502 if (total_width > max_width && Vsplit_long_rows) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2503 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2504 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2505 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2506 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2507 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2508 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2509 max_width -= extra_indent; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2510 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2511 if (max_width < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2512 max_width = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2513 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
2514 pr_scale_header (os, fmt.scale_factor ()); |
10315
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 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2517 while (col < num_elem) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2518 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2519 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
|
2520 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2521 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
|
2522 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2523 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2524 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2525 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2526 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
|
2527 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2528 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2529 |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2530 double val; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2531 if (i == 0) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2532 val = base; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2533 else |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2534 val = base + i * increment; |
10315
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 if (i == num_elem - 1) |
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 // 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
|
2539 if ((increment > 0 && val >= limit) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2540 || (increment < 0 && val <= limit)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2541 val = limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2542 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2543 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2544 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2545 |
24787
168d5b43c840
store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents:
24786
diff
changeset
|
2546 pr_float (os, fmt, val); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2547 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2548 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2549 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2550 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2551 } |
1 | 2552 } |
2553 } | |
2554 | |
1343 | 2555 void |
3523 | 2556 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
|
2557 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2558 int extra_indent) |
3215 | 2559 { |
21583
d5963a6e29c2
Use integer output formatting for logicals (bug #47607)
Mike Miller <mtmiller@octave.org>
parents:
21568
diff
changeset
|
2560 uint8NDArray tmp (bm); |
3215 | 2561 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); |
2562 } | |
2563 | |
2564 void | |
4513 | 2565 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
|
2566 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2567 int extra_indent) |
4513 | 2568 { |
2569 switch (nda.ndims ()) | |
2570 { | |
2571 case 1: | |
2572 case 2: | |
19317
25f535b90e52
Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.
Carnë Draug <carandraug@octave.org>
parents:
19255
diff
changeset
|
2573 octave_print_internal (os, boolMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2574 pr_as_read_syntax, extra_indent); |
4513 | 2575 break; |
2576 | |
2577 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2578 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
|
2579 boolMatrix> (os, nda, pr_as_read_syntax); |
4513 | 2580 break; |
2581 } | |
2582 } | |
2583 | |
2584 void | |
3523 | 2585 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
|
2586 bool pr_as_read_syntax, |
21066
258c787cd9ce
maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
2587 int /* FIXME: extra_indent */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2588 bool pr_as_string) |
1343 | 2589 { |
1572 | 2590 if (pr_as_string) |
2591 { | |
5275 | 2592 octave_idx_type nstr = chm.rows (); |
1343 | 2593 |
1572 | 2594 if (pr_as_read_syntax && nstr > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2595 os << "[ "; |
1343 | 2596 |
2907 | 2597 if (nstr != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2598 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2599 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
|
2600 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2601 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2602 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2603 std::string row = chm.row_as_string (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2604 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2605 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2606 { |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25569
diff
changeset
|
2607 os << '"' << octave::undo_string_escapes (row) << '"'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2608 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2609 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2610 os << "; "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2611 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2612 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2613 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2614 os << row; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2615 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2616 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2617 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2618 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2619 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2620 } |
1572 | 2621 |
2622 if (pr_as_read_syntax && nstr > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2623 os << " ]"; |
1343 | 2624 } |
1572 | 2625 else |
2626 { | |
2627 os << "sorry, printing char matrices not implemented yet\n"; | |
2628 } | |
1343 | 2629 } |
2630 | |
4513 | 2631 void |
2632 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
|
2633 bool pr_as_read_syntax, int extra_indent, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2634 bool pr_as_string) |
4513 | 2635 { |
2636 switch (nda.ndims ()) | |
2637 { | |
2638 case 1: | |
2639 case 2: | |
19318
6c9ea5be96bf
Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents:
19317
diff
changeset
|
2640 octave_print_internal (os, charMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2641 pr_as_read_syntax, extra_indent, pr_as_string); |
4513 | 2642 break; |
2643 | |
2644 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2645 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
|
2646 pr_as_read_syntax); |
4513 | 2647 break; |
2648 } | |
2649 } | |
2650 | |
4655 | 2651 void |
4925 | 2652 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
|
2653 bool pr_as_read_syntax, int extra_indent) |
4925 | 2654 { |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2655 Array<std::string> nda (dim_vector (1, 1), s); |
4925 | 2656 |
2657 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent); | |
2658 } | |
2659 | |
2660 void | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2661 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
|
2662 bool pr_as_read_syntax, int /* extra_indent */) |
4655 | 2663 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2664 // 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
|
2665 // function. Can fix this with std::is_same from C++11. |
4655 | 2666 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
2667 if (nda.isempty ()) |
4655 | 2668 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
|
2669 else if (nda.numel () == 1) |
4655 | 2670 { |
2671 os << nda(0); | |
2672 } | |
2673 else | |
2674 { | |
2675 int ndims = nda.ndims (); | |
2676 | |
2677 dim_vector dims = nda.dims (); | |
2678 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2679 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 2680 |
2681 octave_idx_type m = 1; | |
4655 | 2682 |
2683 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2684 m *= dims(i); |
4655 | 2685 |
5275 | 2686 octave_idx_type nr = dims(0); |
2687 octave_idx_type nc = dims(1); | |
2688 | |
2689 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
|
2690 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2691 std::string nm = "ans"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2692 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2693 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2694 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2695 nm += "(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2696 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2697 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2698 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2699 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2700 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2701 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2702 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2703 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
|
2704 buf << ','; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2705 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2706 buf << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2707 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2708 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2709 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2710 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2711 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2712 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
|
2713 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2714 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2715 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2716 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2717 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2718 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2719 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2720 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
|
2721 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2722 // 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
|
2723 // in neatly aligned columns... |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2724 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2725 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2726 octave_idx_type n_cols = page.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2727 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2728 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2729 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2730 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2731 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2732 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
|
2733 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2734 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
|
2735 os << " " << page(ii,jj); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2736 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2737 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2738 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2739 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2740 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2741 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2742 |
26501
cfe28edab48b
pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
2743 increment_index (ra_idx, dims, 2); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2744 } |
4655 | 2745 } |
2746 } | |
2747 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
2748 template <typename T> |
4901 | 2749 class |
2750 octave_print_conv | |
2751 { | |
2752 public: | |
2753 typedef T print_conv_type; | |
2754 }; | |
2755 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2756 #define PRINT_CONV(T1, T2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2757 template <> \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2758 class \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2759 octave_print_conv<T1> \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2760 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2761 public: \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2762 typedef T2 print_conv_type; \ |
4901 | 2763 } |
2764 | |
2765 PRINT_CONV (octave_int8, octave_int16); | |
2766 PRINT_CONV (octave_uint8, octave_uint16); | |
2767 | |
2768 #undef PRINT_CONV | |
2769 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
2770 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2771 static inline void |
4949 | 2772 pr_int (std::ostream& os, const T& d, int fw = 0) |
2773 { | |
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
|
2774 size_t sz = d.byte_size (); |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23410
diff
changeset
|
2775 const unsigned char *tmpi = d.iptr (); |
4949 | 2776 |
5544 | 2777 // Unless explicitly asked for, always print in big-endian |
2778 // format for hex and bit formats. | |
2779 // | |
2780 // {bit,hex}_format == 1: print big-endian | |
2781 // {bit,hex}_format == 2: print native | |
2782 | |
4949 | 2783 if (hex_format) |
2784 { | |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2785 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
|
2786 |
27459
36b610122086
Correctly display integer types with format hex (bug #56966).
Rik <rik@octave.org>
parents:
27458
diff
changeset
|
2787 os.fill ('0'); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2788 os.flags (std::ios::right | std::ios::hex); |
4949 | 2789 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
2790 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
|
2791 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2792 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2793 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
|
2794 } |
4949 | 2795 else |
10315
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 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2798 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
|
2799 } |
4949 | 2800 } |
2801 else if (bit_format) | |
2802 { | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
2803 if (octave::mach_info::words_big_endian ()) |
10315
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 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2806 PRINT_CHAR_BITS (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2807 } |
4949 | 2808 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2809 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2810 if (bit_format > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2811 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2812 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2813 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2814 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2815 else |
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 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2818 PRINT_CHAR_BITS (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2819 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2820 } |
4949 | 2821 } |
2822 else | |
2823 { | |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2824 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
|
2825 |
4949 | 2826 os << std::setw (fw) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2827 << typename octave_print_conv<T>::print_conv_type (d); |
4949 | 2828 |
2829 if (bank_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2830 os << ".00"; |
4949 | 2831 } |
2832 } | |
2833 | |
7215 | 2834 template void |
2835 pr_int (std::ostream&, const octave_int8&, int); | |
2836 | |
2837 template void | |
2838 pr_int (std::ostream&, const octave_int16&, int); | |
2839 | |
2840 template void | |
2841 pr_int (std::ostream&, const octave_int32&, int); | |
2842 | |
2843 template void | |
2844 pr_int (std::ostream&, const octave_int64&, int); | |
2845 | |
2846 template void | |
2847 pr_int (std::ostream&, const octave_uint8&, int); | |
2848 | |
2849 template void | |
2850 pr_int (std::ostream&, const octave_uint16&, int); | |
2851 | |
2852 template void | |
2853 pr_int (std::ostream&, const octave_uint32&, int); | |
2854 | |
2855 template void | |
2856 pr_int (std::ostream&, const octave_uint64&, int); | |
2857 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
2858 template <typename T> |
4901 | 2859 void |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
2860 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
|
2861 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
|
2862 const octave_int<T>& val, bool) |
7215 | 2863 { |
2864 if (plus_format) | |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
2865 pr_plus_format (os, val); |
7215 | 2866 else |
2867 { | |
2868 if (free_format) | |
23534
b6498c088fca
maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
2869 os << typename octave_print_conv<octave_int<T>>::print_conv_type (val); |
7215 | 2870 else |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
2871 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
2872 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
|
2873 |
27183
2d9decd77e58
revamp float_format object
John W. Eaton <jwe@octave.org>
parents:
27156
diff
changeset
|
2874 pr_int (os, val, r_fmt.width ()); |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
2875 } |
7215 | 2876 } |
2877 } | |
2878 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2879 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2880 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
|
2881 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
|
2882 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
|
2883 const octave_int<TYPE>& val, bool dummy) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2884 { \ |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
2885 octave_print_internal_template (os, fmt, val, dummy); \ |
7215 | 2886 } |
2887 | |
2888 PRINT_INT_SCALAR_INTERNAL (int8_t) | |
2889 PRINT_INT_SCALAR_INTERNAL (uint8_t) | |
2890 PRINT_INT_SCALAR_INTERNAL (int16_t) | |
2891 PRINT_INT_SCALAR_INTERNAL (uint16_t) | |
2892 PRINT_INT_SCALAR_INTERNAL (int32_t) | |
2893 PRINT_INT_SCALAR_INTERNAL (uint32_t) | |
2894 PRINT_INT_SCALAR_INTERNAL (int64_t) | |
2895 PRINT_INT_SCALAR_INTERNAL (uint64_t) | |
2896 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
2897 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2898 static inline void |
7215 | 2899 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
|
2900 bool pr_as_read_syntax, int extra_indent) |
4901 | 2901 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2902 // 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
|
2903 // function. Can fix this with std::is_same from C++11. |
4901 | 2904 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
2905 if (nda.isempty ()) |
4901 | 2906 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
|
2907 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
|
2908 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
|
2909 pr_as_read_syntax); |
4949 | 2910 else if (plus_format && ! pr_as_read_syntax) |
4901 | 2911 { |
2912 int ndims = nda.ndims (); | |
2913 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2914 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
4949 | 2915 |
4901 | 2916 dim_vector dims = nda.dims (); |
2917 | |
5275 | 2918 octave_idx_type m = 1; |
4901 | 2919 |
2920 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2921 m *= dims(i); |
4901 | 2922 |
5275 | 2923 octave_idx_type nr = dims(0); |
2924 octave_idx_type nc = dims(1); | |
2925 | |
2926 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
|
2927 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2928 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2929 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2930 std::string nm = "ans(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2931 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2932 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2933 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2934 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2935 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2936 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2937 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2938 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
|
2939 buf << ','; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2940 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2941 buf << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2942 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2943 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2944 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2945 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2946 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2947 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2948 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2949 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2950 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2951 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
|
2952 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2953 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2954 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2955 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2956 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2957 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2958 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2959 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
|
2960 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2961 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
|
2962 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2963 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
|
2964 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2965 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2966 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2967 pr_plus_format (os, page(ii,jj)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2968 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2969 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2970 if ((ii < nr - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2971 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2972 } |
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 (i < 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 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2977 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2978 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2979 } |
4949 | 2980 } |
2981 else | |
2982 { | |
2983 int ndims = nda.ndims (); | |
2984 | |
2985 dim_vector dims = nda.dims (); | |
2986 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2987 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 2988 |
2989 octave_idx_type m = 1; | |
4949 | 2990 |
2991 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2992 m *= dims(i); |
4949 | 2993 |
5275 | 2994 octave_idx_type nr = dims(0); |
2995 octave_idx_type nc = dims(1); | |
4949 | 2996 |
2997 int fw = 0; | |
2998 if (hex_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2999 fw = 2 * nda(0).byte_size (); |
4949 | 3000 else if (bit_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3001 fw = nda(0).nbits (); |
4949 | 3002 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3003 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3004 bool isneg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3005 int digits = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3006 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3007 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
|
3008 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3009 int new_digits |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3010 = static_cast<int> |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
3011 (std::floor (log10 (double (abs (nda(i).value ()))) + 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3012 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3013 if (new_digits > digits) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3014 digits = new_digits; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3015 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3016 if (! isneg) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3017 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
|
3018 } |
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 fw = digits + isneg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3021 } |
4949 | 3022 |
6788 | 3023 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2)); |
5275 | 3024 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
|
3025 int max_width = octave::command_editor::terminal_cols () - extra_indent; |
5275 | 3026 octave_idx_type inc = nc; |
4949 | 3027 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
|
3028 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3029 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3030 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3031 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3032 } |
4949 | 3033 |
5275 | 3034 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
|
3035 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3036 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3037 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3038 std::string nm = "ans(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3039 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3040 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3041 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3042 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3043 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3044 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3045 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3046 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
|
3047 buf << ','; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3048 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3049 buf << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3050 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3051 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3052 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3053 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3054 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3055 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3056 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3057 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3058 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3059 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
|
3060 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3061 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3062 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3063 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3064 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3065 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3066 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3067 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
|
3068 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3069 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3070 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3071 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3072 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3073 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3074 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
|
3075 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3076 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
|
3077 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3078 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3079 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3080 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
|
3081 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3082 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3083 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3084 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3085 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
|
3086 os << ']'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3087 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3088 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3089 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
3090 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
|
3091 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3092 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3093 octave_idx_type n_cols = page.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3094 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3095 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
|
3096 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
3097 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
|
3098 : n_cols); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3099 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3100 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
|
3101 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3102 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3103 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
|
3104 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3105 os << std::setw (extra_indent) << ""; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3106 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3107 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
|
3108 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3109 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3110 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3111 pr_int (os, page(ii,jj), fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3112 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3113 if ((ii < n_rows - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3114 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3115 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3116 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3117 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3118 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3119 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3120 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3121 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3122 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3123 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3124 } |
4901 | 3125 } |
3126 } | |
3127 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3128 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3129 OCTINTERP_API void \ |
7215 | 3130 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
|
3131 bool pr_as_read_syntax, int extra_indent) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3132 { \ |
7215 | 3133 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \ |
3134 } | |
3135 | |
3136 PRINT_INT_ARRAY_INTERNAL (octave_int8) | |
3137 PRINT_INT_ARRAY_INTERNAL (octave_uint8) | |
3138 PRINT_INT_ARRAY_INTERNAL (octave_int16) | |
3139 PRINT_INT_ARRAY_INTERNAL (octave_uint16) | |
3140 PRINT_INT_ARRAY_INTERNAL (octave_int32) | |
3141 PRINT_INT_ARRAY_INTERNAL (octave_uint32) | |
3142 PRINT_INT_ARRAY_INTERNAL (octave_int64) | |
3143 PRINT_INT_ARRAY_INTERNAL (octave_uint64) | |
4901 | 3144 |
8012
63dbb85452cc
fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents:
7896
diff
changeset
|
3145 void |
3933 | 3146 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) |
3928 | 3147 { |
3933 | 3148 panic_impossible (); |
3928 | 3149 } |
3150 | |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3151 void |
19620
a1d172bfcb2f
eliminate some unused variable and typedef warnings
John W. Eaton <jwe@octave.org>
parents:
19367
diff
changeset
|
3152 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
|
3153 { |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3154 panic_impossible (); |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3155 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3156 |
20915
a3359fe50966
remove unused nargout variables
John W. Eaton <jwe@octave.org>
parents:
20909
diff
changeset
|
3157 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
|
3158 doc: /* -*- texinfo -*- |
27154
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3159 @deftypefn {} {@var{s} =} rats (@var{x}) |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3160 @deftypefnx {} {@var{s} =} rats (@var{x}, @var{len}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3161 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
|
3162 |
27154
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3163 A rational approximation to a floating point number is a simple fraction |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3164 with numerator @var{N} and denominator @var{D} such that |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3165 @code{@var{x} = @var{N}/@var{D}}. |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3166 |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3167 The optional second argument defines the maximum length of the string |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3168 representing the elements of @var{x}. By default, @var{len} is 9. |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3169 |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3170 If the length of the smallest possible rational approximation exceeds |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3171 @var{len}, an asterisk (*) padded with spaces will be returned instead. |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3172 |
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3173 Example conversion from matrix to string, and back again. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3174 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3175 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3176 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3177 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
|
3178 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
|
3179 @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
|
3180 @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
|
3181 |
27154
ecc16b72bfb3
doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3182 @seealso{rat, format} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3183 @end deftypefn */) |
6788 | 3184 { |
3185 int nargin = args.length (); | |
3186 | |
20909
03e4ddd49396
omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents:
20897
diff
changeset
|
3187 if (nargin < 1 || nargin > 2) |
7896 | 3188 print_usage (); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3189 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3190 octave_value arg = args(0); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3191 |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
3192 if (! arg.isnumeric ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3193 error ("rats: X must be numeric"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3194 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
3195 octave::unwind_protect frame; |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3196 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3197 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
|
3198 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3199 rat_string_len = 9; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3200 if (nargin == 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3201 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
|
3202 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3203 frame.protect_var (rat_format); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3204 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3205 rat_format = true; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3206 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3207 std::ostringstream buf; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3208 arg.print (buf); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3209 std::string s = buf.str (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3210 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3211 std::list<std::string> lst; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3212 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3213 size_t n = 0; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3214 size_t s_len = s.length (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3215 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3216 while (n < s_len) |
6788 | 3217 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3218 size_t m = s.find ('\n', n); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3219 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3220 if (m == std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3221 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3222 lst.push_back (s.substr (n)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3223 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3224 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3225 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3226 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3227 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
|
3228 n = m + 1; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3229 } |
6788 | 3230 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3231 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3232 return ovl (string_vector (lst)); |
6788 | 3233 } |
3234 | |
26111
3e44ed9d50b6
Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26009
diff
changeset
|
3235 /* |
3e44ed9d50b6
Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26009
diff
changeset
|
3236 %!test |
26716
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3237 %! [old_fmt, old_spacing] = format (); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3238 %! unwind_protect |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3239 %! format short; |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3240 %! assert (rats (2.0005, 9), "4001/2000"); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3241 %! assert (rats (-2.0005, 10), "-4001/2000"); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3242 %! assert (strtrim (rats (2.0005, 30)), "4001/2000"); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3243 %! assert (pi - str2num (rats (pi, 30)), 0, 4 * eps); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3244 %! assert (e - str2num (rats (e, 30)), 0, 4 * eps); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3245 %! assert (rats (123, 2), " *"); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3246 %! v = 1 / double (intmax); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3247 %! err = v - str2num (rats (v, 12)); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3248 %! assert (err, 0, 4 * eps); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3249 %! unwind_protect_cleanup |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3250 %! format (old_fmt); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3251 %! format (old_spacing); |
daa281e03d9a
Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents:
26585
diff
changeset
|
3252 %! end_unwind_protect |
26111
3e44ed9d50b6
Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26009
diff
changeset
|
3253 */ |
3e44ed9d50b6
Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26009
diff
changeset
|
3254 |
3685 | 3255 DEFUN (disp, args, nargout, |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3256 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
|
3257 doc: /* -*- texinfo -*- |
24764
36ca11f78553
Document second calling form of disp().
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
3258 @deftypefn {} {} disp (@var{x}) |
36ca11f78553
Document second calling form of disp().
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
3259 @deftypefnx {} {@var{str} =} disp (@var{x}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3260 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
|
3261 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3262 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
|
3263 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3264 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3265 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3266 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
|
3267 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3268 @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
|
3269 @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
|
3270 @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
|
3271 @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
|
3272 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3273 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3274 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
|
3275 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3276 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
|
3277 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
|
3278 @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
|
3279 @end deftypefn */) |
3685 | 3280 { |
20909
03e4ddd49396
omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents:
20897
diff
changeset
|
3281 if (args.length () != 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3282 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3283 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3284 octave_value_list retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3285 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3286 octave_value arg = args(0); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3287 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3288 if (nargout == 0) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3289 arg.print (octave_stdout); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3290 else |
3685 | 3291 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3292 std::ostringstream buf; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3293 arg.print (buf); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
3294 retval = (octave_value (buf.str (), arg.is_dq_string () ? '"' : '\'')); |
3685 | 3295 } |
3296 | |
3297 return retval; | |
3298 } | |
3299 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3300 DEFMETHOD (fdisp, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3301 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
|
3302 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
|
3303 @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
|
3304 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
|
3305 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3306 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
|
3307 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3308 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3309 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3310 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
|
3311 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3312 @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
|
3313 @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
|
3314 @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
|
3315 @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
|
3316 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3317 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3318 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
|
3319 @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
|
3320 @end deftypefn */) |
3685 | 3321 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
3322 if (args.length () != 2) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3323 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3324 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3325 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
|
3326 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3327 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
|
3328 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3329 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
|
3330 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3331 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
|
3332 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3333 octave_value arg = args(1); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3334 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3335 if (osp) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3336 arg.print (*osp); |
3685 | 3337 else |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3338 error ("fdisp: stream FID not open for writing"); |
3685 | 3339 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
3340 return ovl (); |
3685 | 3341 } |
3342 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3343 /* |
25108
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3344 ## FIXME: This test writes values to a file, but then never checks them. |
9629 | 3345 %!test |
25108
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3346 %! [old_fmt, old_spacing] = format (); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3347 %! unwind_protect |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3348 %! format short |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3349 %! fd = tmpfile (); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3350 %! for r = [0, Inf -Inf, NaN] |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3351 %! for i = [0, Inf -Inf, NaN] |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3352 %! fdisp (fd, complex (r, i)); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3353 %! endfor |
9629 | 3354 %! endfor |
25108
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3355 %! fclose (fd); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3356 %! unwind_protect_cleanup |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3357 %! format (old_fmt); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3358 %! format (old_spacing); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3359 %! end_unwind_protect |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3360 |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3361 %!test |
25108
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3362 %! [old_fmt, old_spacing] = format (); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3363 %! unwind_protect |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3364 %! foo.real = pi * ones (3,20,3); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3365 %! foo.complex = pi * ones (3,20,3) + 1i; |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3366 %! foo.char = repmat ("- Hello World -", [3, 20]); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3367 %! foo.cell = {foo.real, foo.complex, foo.char}; |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3368 %! fields = fieldnames (foo); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3369 %! for f = 1:numel (fields) |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3370 %! format loose; |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3371 %! loose = disp (foo.(fields{f})); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3372 %! format compact; |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3373 %! compact = disp (foo.(fields{f})); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3374 %! expected = strrep (loose, "\n\n", "\n"); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3375 %! assert (expected, compact); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3376 %! endfor |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3377 %! unwind_protect_cleanup |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3378 %! format (old_fmt); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3379 %! format (old_spacing); |
7561fb4ab972
pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents:
25107
diff
changeset
|
3380 %! end_unwind_protect |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3381 */ |
9629 | 3382 |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3383 DEFUN (display, args, , |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3384 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
|
3385 doc: /* -*- texinfo -*- |
23565
3a730821e4a2
doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents:
23564
diff
changeset
|
3386 @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
|
3387 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
|
3388 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3389 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
|
3390 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
|
3391 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
|
3392 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3393 @example |
23182
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3394 myclass (@dots{}) |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3395 @end example |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3396 |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3397 Or: |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3398 |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3399 @example |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3400 myobj = myclass (@dots{}) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3401 @end example |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3402 |
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
|
3403 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
|
3404 avoid the default output: |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3405 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3406 @example |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3407 @group |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3408 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
|
3409 @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
|
3410 |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3411 <class myclass> |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3412 @end group |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3413 @end example |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3414 |
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
|
3415 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
|
3416 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
|
3417 @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
|
3418 |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3419 @seealso{disp, class, subsref, subsasgn} |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3420 @end deftypefn */) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3421 { |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3422 int nargin = args.length (); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3423 |
23332
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3424 // 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
|
3425 // 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
|
3426 // 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
|
3427 // 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
|
3428 |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3429 if (nargin < 1 || nargin > 2) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3430 print_usage (); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3431 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3432 std::string name; |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3433 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3434 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
|
3435 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
|
3436 else |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3437 { |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3438 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
|
3439 name = names(0); |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3440 } |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3441 |
23332
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3442 // 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
|
3443 // object type. |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3444 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3445 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
|
3446 |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3447 // 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
|
3448 // disp is done. |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3449 |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3450 bool print_newlines = false; |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25569
diff
changeset
|
3451 if (octave::valid_identifier (name)) |
22989
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3452 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
|
3453 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3454 // 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
|
3455 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23059
diff
changeset
|
3456 octave::feval ("disp", ovl (value)); |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3457 |
22989
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3458 if (print_newlines) |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3459 octave_stdout << std::endl; |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3460 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3461 return ovl (); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3462 } |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3463 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3464 /* |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3465 %!test |
26585
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3466 %! [old_fmt, old_spacing] = format (); |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3467 %! unwind_protect |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3468 %! format short; |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3469 %! str = evalc ("x = 1.1; display (x)"); |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
3470 %! assert (str, "x = 1.1000\n"); |
26585
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3471 %! unwind_protect_cleanup |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3472 %! format (old_fmt); |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3473 %! format (old_spacing); |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3474 %! end_unwind_protect |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3475 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3476 %!test |
26585
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3477 %! [old_fmt, old_spacing] = format (); |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3478 %! unwind_protect |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3479 %! format short; |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3480 %! str = evalc ("display (1.1)"); |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
3481 %! assert (str, "1.1000\n"); |
26585
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3482 %! unwind_protect_cleanup |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3483 %! format (old_fmt); |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3484 %! format (old_spacing); |
d673b506f382
test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents:
26501
diff
changeset
|
3485 %! end_unwind_protect |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3486 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3487 ## Test input validation |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3488 %!error display () |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3489 %!error display (1,2) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3490 */ |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3491 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
3492 static inline void |
1 | 3493 init_format_state (void) |
3494 { | |
2387 | 3495 free_format = false; |
3496 plus_format = false; | |
6788 | 3497 rat_format = false; |
2387 | 3498 bank_format = false; |
3608 | 3499 hex_format = 0; |
1309 | 3500 bit_format = 0; |
2387 | 3501 print_e = false; |
3502 print_big_e = false; | |
4509 | 3503 print_g = false; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3504 print_eng = false; |
1 | 3505 } |
3506 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3507 static std::string format_string ("short"); |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
3508 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
3509 static inline void |
1755 | 3510 set_format_style (int argc, const string_vector& argv) |
1 | 3511 { |
1755 | 3512 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
|
3513 std::string format; |
1755 | 3514 |
1899 | 3515 if (--argc > 0) |
1 | 3516 { |
3523 | 3517 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
|
3518 format = arg; |
2584 | 3519 |
1755 | 3520 if (arg == "short") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3521 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3522 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3523 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3524 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
|
3525 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3526 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3527 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3528 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3529 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3530 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3531 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3532 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3533 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3534 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3535 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3536 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3537 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3538 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3539 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3540 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3541 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3542 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3543 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3544 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3545 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3546 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3547 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3548 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3549 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3550 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3551 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3552 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3553 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3554 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3555 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
|
3556 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3557 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3558 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3559 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3560 set_output_prec (5); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3561 } |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3562 else if (arg == "shorte") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3563 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3564 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3565 print_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3566 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3567 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3568 else if (arg == "shortE") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3569 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3570 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3571 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3572 print_big_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3573 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3574 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3575 else if (arg == "shortg") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3576 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3577 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3578 print_g = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3579 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3580 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3581 else if (arg == "shortG") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3582 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3583 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3584 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3585 print_big_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3586 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3587 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3588 else if (arg == "shortEng") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3589 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3590 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3591 print_eng = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3592 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3593 } |
1755 | 3594 else if (arg == "long") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3595 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3596 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3597 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3598 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
|
3599 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3600 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3601 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3602 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3603 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3604 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3605 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3606 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3607 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3608 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3609 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3610 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3611 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3612 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3613 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3614 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3615 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3616 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3617 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3618 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3619 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3620 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3621 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3622 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3623 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3624 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3625 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3626 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3627 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3628 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3629 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
|
3630 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3631 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3632 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3633 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3634 set_output_prec (16); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3635 } |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3636 else if (arg == "longe") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3637 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3638 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3639 print_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3640 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3641 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3642 else if (arg == "longE") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3643 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3644 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3645 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3646 print_big_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3647 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3648 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3649 else if (arg == "longg") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3650 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3651 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3652 print_g = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3653 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3654 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3655 else if (arg == "longG") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3656 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3657 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3658 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3659 print_big_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3660 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3661 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3662 else if (arg == "longEng") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3663 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3664 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3665 print_eng = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3666 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3667 } |
1755 | 3668 else if (arg == "hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3669 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3670 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3671 hex_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3672 } |
1755 | 3673 else if (arg == "native-hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3674 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3675 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3676 hex_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3677 } |
1755 | 3678 else if (arg == "bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3679 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3680 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3681 bit_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3682 } |
1755 | 3683 else if (arg == "native-bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3684 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3685 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3686 bit_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3687 } |
1755 | 3688 else if (arg == "+" || arg == "plus") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3689 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3690 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3691 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3692 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
|
3693 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3694 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3695 if (arg.length () == 3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3696 plus_format_chars = arg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3697 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3698 error ("format: invalid option for plus format"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3699 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3700 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
|
3701 plus_format_chars = "+- "; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3702 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3703 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3704 plus_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3705 } |
6788 | 3706 else if (arg == "rat") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3707 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3708 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3709 rat_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3710 } |
1755 | 3711 else if (arg == "bank") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3712 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3713 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3714 bank_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3715 } |
1755 | 3716 else if (arg == "free") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3717 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3718 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3719 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3720 } |
1755 | 3721 else if (arg == "none") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3722 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3723 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3724 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3725 } |
1755 | 3726 else if (arg == "compact") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3727 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3728 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
|
3729 return; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3730 } |
1755 | 3731 else if (arg == "loose") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3732 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3733 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
|
3734 return; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3735 } |
1 | 3736 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3737 error ("format: unrecognized format state '%s'", arg.c_str ()); |
1 | 3738 } |
3739 else | |
3740 { | |
3741 init_format_state (); | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3742 set_output_prec (5); |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
3743 format = "short"; |
25107
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3744 Vcompact_format = false; |
1 | 3745 } |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3746 |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3747 format_string = format; |
1 | 3748 } |
3749 | |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3750 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
|
3751 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
|
3752 @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
|
3753 @deftypefnx {} {} format options |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3754 @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
|
3755 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
|
3756 normal echoing mechanism. |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3757 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3758 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
|
3759 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
|
3760 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
|
3761 @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
|
3762 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3763 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
|
3764 (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
|
3765 @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
|
3766 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3767 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
|
3768 table. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3769 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3770 @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
|
3771 @item short |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3772 Fixed point format with 5 significant figures (default). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3773 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3774 @item long |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3775 Fixed point format with 16 significant figures. |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3776 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3777 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
|
3778 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
|
3779 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3780 @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
|
3781 @itemx long e |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3782 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
|
3783 and an exponent (power of 10). The mantissa has 5 significant digits in the |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3784 short format. In the long format, double values are displayed with 16 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3785 significant digits and single values are displayed with 8. For example, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3786 with the @samp{short e} format, @code{pi} is displayed as @code{3.1416e+00}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3787 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3788 @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
|
3789 @itemx long E |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3790 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
|
3791 to indicate the exponent. For example, with the @samp{long E} format, |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3792 @code{pi} is displayed as @code{3.141592653589793E+00}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3793 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3794 @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
|
3795 @itemx long g |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3796 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
|
3797 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
|
3798 @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
|
3799 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3800 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3801 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3802 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3803 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3804 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
|
3805 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
|
3806 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
|
3807 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
|
3808 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
|
3809 @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
|
3810 @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
|
3811 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3812 @item 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
|
3813 @itemx long eng |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3814 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
|
3815 engineering format, where the exponent is divisible by 3. For example, with |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3816 the @samp{short eng} format, @code{10 * pi} is displayed as @code{31.416e+00}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3817 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3818 @item 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
|
3819 @itemx short G |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3820 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
|
3821 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
|
3822 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3823 @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
|
3824 @itemx none |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3825 Print output in free format, without trying to line up columns of matrices on |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3826 the decimal point. This is a raw format equivalent to the C++ code |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3827 @code{std::cout << @var{variable}}. In general, the result is a presentation |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3828 with 6 significant digits where unnecessary precision (such as trailing zeros |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3829 for integers) is suppressed. Complex numbers are formatted as numeric pairs |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3830 like this @samp{(0.60419, 0.60709)} instead of like this |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3831 @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
|
3832 @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
|
3833 |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3834 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
|
3835 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
|
3836 |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3837 @table @asis |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3838 @item @qcode{"+"} |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3839 @itemx @qcode{"+"} @qcode{"@var{chars}"} |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3840 @itemx @code{plus} |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3841 @itemx @code{plus @var{chars}} |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3842 Print a @samp{+} symbol for matrix elements greater than zero, a @samp{-} |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3843 symbol for elements less than zero, and a space for zero matrix elements. This |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3844 format can be useful for examining the sparsity structure of a large matrix. |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3845 For very large matrices the function @code{spy} which plots the sparsity |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3846 pattern will be clearer. |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3847 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3848 The optional argument @var{chars} specifies a list of 3 characters to use for |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3849 printing values greater than zero, less than zero, and equal to zero. For |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3850 example, with the format @qcode{"+" "+-."}, the matrix |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3851 @code{[1, 0, -1; -1, 0, 1]} is displayed as |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3852 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3853 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3854 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3855 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3856 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3857 +.- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3858 -.+ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3859 @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
|
3860 @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
|
3861 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3862 @item bank |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3863 Print variable in a format appropriate for a currency (fixed format with two |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3864 digits to the right of the decimal point). Only the real part of a variable is |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
3865 displayed, as the imaginary part makes no sense for a currency. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3866 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3867 @item native-hex |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3868 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
|
3869 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
|
3870 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
|
3871 @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
|
3872 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3873 @item hex |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3874 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
|
3875 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
|
3876 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3877 @item native-bit |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3878 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
|
3879 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
|
3880 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3881 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3882 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3883 01000000000010010010000111111011 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3884 01010100010001000010110100011000 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3885 @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
|
3886 @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
|
3887 |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3888 (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
|
3889 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
|
3890 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
|
3891 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3892 @item bit |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3893 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
|
3894 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
|
3895 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3896 @item rat |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3897 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
|
3898 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
|
3899 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
|
3900 @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
|
3901 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3902 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
|
3903 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3904 @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
|
3905 @item compact |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3906 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
|
3907 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
|
3908 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3909 @item loose |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3910 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
|
3911 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
|
3912 @end table |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3913 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3914 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
|
3915 format and format spacing. |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3916 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3917 @seealso{fixed_point_format, output_precision, split_long_rows, print_empty_dimensions, rats} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3918 @end deftypefn */) |
529 | 3919 { |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3920 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
|
3921 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3922 if (nargout == 0) |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3923 { |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3924 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
|
3925 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3926 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
|
3927 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3928 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
|
3929 } |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3930 else |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3931 { |
25107
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3932 if (args.length () > 0) |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3933 warning ("format: cannot query and set format at the same time, ignoring set operation"); |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3934 |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3935 if (nargout >= 2) |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
3936 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
|
3937 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3938 retval(0) = format_string; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3939 } |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3940 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3941 return retval; |
529 | 3942 } |
3943 | |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3944 /* |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3945 %!test |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3946 %! [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
|
3947 %! unwind_protect |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3948 %! ## 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
|
3949 %! format long; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3950 %! str = disp (pi); |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
3951 %! assert (str, "3.141592653589793\n"); |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3952 %! str = disp (single (pi)); |
27458
2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents:
27454
diff
changeset
|
3953 %! assert (str, "3.1415927\n"); |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3954 %! new_fmt = format (); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3955 %! assert (new_fmt, "long"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3956 %! ## Test resetting format |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3957 %! format compact; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3958 %! [~, new_spacing] = format (); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3959 %! assert (new_spacing, "compact"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3960 %! format; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3961 %! [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
|
3962 %! assert (new_fmt, "short"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3963 %! assert (new_spacing, "loose"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3964 %! unwind_protect_cleanup |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3965 %! format (old_fmt); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3966 %! format (old_spacing); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3967 %! end_unwind_protect |
25107
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3968 |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3969 %!test <*53427> |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3970 %! [old_fmt, old_spacing] = format (); |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3971 %! unwind_protect |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3972 %! format; # reset format to short and loose |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3973 %! format compact; # set compact format |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3974 %! format long; # set long format |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3975 %! [fmt, spacing] = format (); |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3976 %! assert (fmt, "long"); |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3977 %! assert (spacing, "compact"); |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3978 %! unwind_protect_cleanup |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3979 %! format (old_fmt); |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3980 %! format (old_spacing); |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3981 %! end_unwind_protect |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3982 |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3983 ## Test input validation |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3984 %!test |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3985 %! fail ("fmt = format ('long')", "warning", "cannot query and set format"); |
13cd142c3f88
Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
3986 |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3987 */ |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3988 |
5794 | 3989 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
|
3990 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
|
3991 @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
|
3992 @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
|
3993 @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
|
3994 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
|
3995 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
|
3996 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3997 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
|
3998 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
|
3999 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
|
4000 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4001 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4002 @group |
26205
cf037b842a9f
doc: Clarify example code in fixed_point_format documentation (bug #55208).
Rik <rik@octave.org>
parents:
26111
diff
changeset
|
4003 fixed_point_format (true) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4004 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
|
4005 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4006 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4007 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
|
4008 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4009 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
|
4010 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
|
4011 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
|
4012 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
|
4013 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
|
4014 @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
|
4015 @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
|
4016 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4017 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4018 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
|
4019 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
|
4020 @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
|
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 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
|
4023 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
|
4024 The original variable value is restored when exiting the function. |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4025 @seealso{format, output_precision} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4026 @end deftypefn */) |
5794 | 4027 { |
4028 return SET_INTERNAL_VARIABLE (fixed_point_format); | |
4029 } | |
4030 | |
4031 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
|
4032 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
|
4033 @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
|
4034 @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
|
4035 @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
|
4036 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
|
4037 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
|
4038 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4039 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
|
4040 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4041 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4042 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
|
4043 @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
|
4044 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4045 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4046 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
|
4047 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4048 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4049 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
|
4050 @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
|
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 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
|
4053 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
|
4054 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
|
4055 @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
|
4056 @end deftypefn */) |
5794 | 4057 { |
4058 return SET_INTERNAL_VARIABLE (print_empty_dimensions); | |
4059 } | |
4060 | |
4061 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
|
4062 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
|
4063 @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
|
4064 @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
|
4065 @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
|
4066 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
|
4067 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
|
4068 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4069 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
|
4070 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
|
4071 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
|
4072 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
|
4073 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4074 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4075 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4076 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
|
4077 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4078 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4079 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
|
4080 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4081 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
|
4082 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
|
4083 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4084 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
|
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 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
|
4087 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
|
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 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
|
4092 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
|
4093 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
|
4094 @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
|
4095 @end deftypefn */) |
5794 | 4096 { |
4097 return SET_INTERNAL_VARIABLE (split_long_rows); | |
4098 } |