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