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