annotate libinterp/corefcn/pr-output.cc @ 31978:1f7958de177f stable

Fix display of scalar complex variables with mixed Inf/NaN and floating point values (bug #63961) * pr-output.cc (make_complex_scalar_format): Skip using isfinite() to influence field with variables r_x and i_x. * pr-output.cc (make_complex_format): Restrict code path for integers to only take place when "int_only" is true (don't take this path when "inf_or_nan" is true). For case of real values, guarantee a minimum fieldwidth of 3 if "inf_or_nan" is true.
author Rik <rik@octave.org>
date Fri, 07 Apr 2023 12:18:28 -0700
parents c1fc1e821381
children 1168f6aa35f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 //
31706
597f3ee61a48 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31660
diff changeset
3 // Copyright (C) 1993-2023 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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
28 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
29
23662
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23619
diff changeset
30 #include <cmath>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
31
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3373
diff changeset
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
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5759
diff changeset
35 #include <sstream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1716
diff changeset
36 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1716
diff changeset
37
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
38 #include "Array-util.h"
453
393e95f46b51 [project @ 1994-06-06 00:05:20 by jwe]
jwe
parents: 296
diff changeset
39 #include "CMatrix.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
40 #include "Range.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
41 #include "cmd-edit.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
42 #include "dMatrix.h"
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2847
diff changeset
43 #include "lo-mappers.h"
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
44 #include "mach-info.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1588
diff changeset
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
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4051
diff changeset
47 #include "quit.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
48
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
49 #include "Cell.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
50 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
51 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21066
diff changeset
52 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
53 #include "ovl.h"
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
54 #include "oct-stream.h"
20925
667861ffffab Extracted header class octave-preserve-stream-state from utils.{cc/h}.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20915
diff changeset
55 #include "octave-preserve-stream-state.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
56 #include "pager.h"
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
57 #include "parse.h"
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
58 #include "pr-flt-fmt.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
59 #include "pr-output.h"
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
60 #include "sysdep.h"
6803
fe19c6cb5bc6 [project @ 2007-07-26 18:04:05 by jwe]
jwe
parents: 6788
diff changeset
61 #include "unwind-prot.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
62 #include "utils.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
63 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
67 static bool Vfixed_point_format = false;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
68
5360
33adb987c033 [project @ 2005-05-23 16:19:56 by jwe]
jwe
parents: 5331
diff changeset
69 // TRUE means that the dimensions of empty objects should be printed
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
70 // like this: x = [](2x0).
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
71 bool Vprint_empty_dimensions = true;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
72
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
73 // TRUE means that the rows of big matrices should be split into
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
74 // smaller slices that fit on the screen.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
75 static bool Vsplit_long_rows = true;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
76
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
77 // TRUE means don't do any fancy formatting.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
78 static bool free_format = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
79
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
80 // TRUE means print plus sign for nonzero, blank for zero.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
81 static bool plus_format = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
82
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
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
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
85
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
86 // TRUE means always print in a rational approximation
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
87 static bool rat_format = false;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
88
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
89 // Used to force the length of the rational approximation string for Frats
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
90 static int rat_string_len = -1;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
91
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
92 // TRUE means always print like dollars and cents.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
93 static bool bank_format = false;
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
94
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
95 // TRUE means print data in hexadecimal format.
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
96 static int hex_format = 0;
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
97
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
98 // TRUE means print data in binary-bit-pattern format.
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
99 static int bit_format = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
100
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
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
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
103
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
104 // TRUE means use an e format.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
105 static bool print_e = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
106
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
107 // TRUE means use a g format.
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
108 static bool print_g = false;
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
123
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
124 // The expression above is equivalent to x - (x % 3).
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
125
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
126 // According to the ISO specification for C++ the modulo operator is
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
127 // compiler dependent if any of the arguments are negative. Since
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
128 // this function will need to work on negative arguments, and we want
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
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
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
131
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
132 // ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO,
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
133 // IEC. 2003 . "the binary % operator yields the remainder from the
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
134 // division of the first expression by the second. .... If both
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
135 // operands are nonnegative then the remainder is nonnegative; if not,
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
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
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
150 // Avoid using modulo function with negative arguments for
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
151 // portability. See extended comment at calc_scale_exp
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
152
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
153 if (logabsval < 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
154 ex = logabsval - 2 + ((-logabsval + 2) % 3);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
155 else
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
156 ex = logabsval - (logabsval % 3);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
157 }
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
158
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
159 return ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
160 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
161
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
162 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
163 static inline int
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
164 num_digits (T x)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
165 {
11450
5eb10763069f substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents: 10987
diff changeset
166 return 1 + (print_eng
5eb10763069f substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents: 10987
diff changeset
167 ? engineering_exponent (x)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
168 : static_cast<int> (std::floor (log10 (x))));
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
169 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
170
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
171 template <typename T>
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
172 int
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
173 pr_engineering_float<T>::exponent (void) const
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
174 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
175 return engineering_exponent (m_val);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
176 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
177
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
178 template <typename T>
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
179 T
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
180 pr_engineering_float<T>::mantissa (void) const
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
181 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
182 return m_val / std::pow (static_cast<T> (10), exponent ());
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
183 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
184
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
185 template <typename T>
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
186 std::ostream&
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
187 operator << (std::ostream& os, const pr_engineering_float<T>& pef)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
188 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
189 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
190
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
191 float_format real_fmt = pef.m_ff;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
192
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
193 if (real_fmt.width () >= 0)
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
194 os << std::setw (real_fmt.width () - real_fmt.exponent_width ());
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
195
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
196 if (real_fmt.precision () >= 0)
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
197 os << std::setprecision (real_fmt.precision ());
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
198
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
199 os.flags (real_fmt.format_flags ());
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
200
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
201 os << pef.mantissa ();
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
202
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
203 int ex = pef.exponent ();
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
204 if (ex < 0)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
205 {
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
206 if (uppercase_format)
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
207 os << std::setw (0) << "E-";
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
208 else
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
209 os << std::setw (0) << "e-";
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
210 ex = -ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
211 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
212 else
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
213 {
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
214 if (uppercase_format)
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
215 os << std::setw (0) << "E+";
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
216 else
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
217 os << std::setw (0) << "e+";
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
218 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
219
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
220 os << std::setw (real_fmt.exponent_width () - 2)
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
221 << std::setfill ('0') << ex;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
222
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
223 return os;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
224 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
225
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
226 template <typename T>
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
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
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
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
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
243
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
244 return os;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
245 }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
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
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
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
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
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
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
263
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
264 if (fw >= 0)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
265 os << std::setw (fw);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
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
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
294
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
295 return os;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
296 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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.
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30588
diff changeset
303 error_unless (m.ndims () == 2);
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
304
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
305 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
306 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
307
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
308 T result = std::numeric_limits<T>::lowest ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
309
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
310 bool all_inf_or_nan = true;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
311
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
312 for (octave_idx_type j = 0; j < nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
313 for (octave_idx_type i = 0; i < nr; i++)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
314 {
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30329
diff changeset
315 T val = m(i, j);
23564
7049da1648c0 Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents: 23534
diff changeset
316 if (! octave::math::isfinite (val))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
317 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
318
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
319 all_inf_or_nan = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
320
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
321 if (val > result)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
322 result = val;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
323 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
324
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
325 if (all_inf_or_nan)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
326 result = 0;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
327
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
328 return result;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
329 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
330
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
331 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
332 static inline T
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
333 pr_min_internal (const MArray<T>& m)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
334 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
335 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
336 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
337
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
338 T result = std::numeric_limits<T>::max ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
339
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
340 bool all_inf_or_nan = true;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
341
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
342 for (octave_idx_type j = 0; j < nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
343 for (octave_idx_type i = 0; i < nr; i++)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
344 {
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30329
diff changeset
345 T val = m(i, j);
23564
7049da1648c0 Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents: 23534
diff changeset
346 if (! octave::math::isfinite (val))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
347 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
348
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
349 all_inf_or_nan = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
350
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
351 if (val < result)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
352 result = val;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
353 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
354
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
355 if (all_inf_or_nan)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
356 result = 0;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
357
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
358 return result;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
359 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
360
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
361 template <typename>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
362 struct pr_output_traits
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
363 {
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
364 static const int DIGITS10;
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
365 static const int MAX_FIELD_WIDTH;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
366 };
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
367
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
368 template <>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
369 struct pr_output_traits<double>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
370 {
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
371 static const int DIGITS10;
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
372 static const int MAX_FIELD_WIDTH;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
373 };
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
374
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
375 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
376 const int pr_output_traits<double>::MAX_FIELD_WIDTH = 21;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
377
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
378 template <>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
379 struct pr_output_traits<float>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
380 {
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
381 static const int DIGITS10;
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
382 static const int MAX_FIELD_WIDTH;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
383 };
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
384
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
385 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
386 const int pr_output_traits<float>::MAX_FIELD_WIDTH = 13;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
387
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
388 // FIXME: it would be nice to share more code among these functions,..
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
389
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
390 // Works for double and float.
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
391
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
392 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
393 static inline float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
394 make_real_format (int digits, bool inf_or_nan, bool int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
395 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
396 float_format fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
397
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
398 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
399
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
400 int fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
401
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
402 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
403 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
404 fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
405 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
406 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
407 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
408 {
27458
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
409 fw = (digits < 0 ? 4 : digits + 3);
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
410 if (inf_or_nan)
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
411 fw = 3;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
412 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
413 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
414 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
415 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
416 fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
417 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
418 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
419 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
420 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
421 fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
422 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
423 }
27458
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
424 else if (inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
425 {
27458
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
426 fw = 3;
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
427 }
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
428 else if (int_only)
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
429 {
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
430 fw = digits;
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
431 ld = digits;
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
432 rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
433 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
434 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
435 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
436 if (digits > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
437 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
438 ld = digits;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
439 rd = (prec > digits ? prec - digits : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
440 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
441 else if (digits < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
442 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
443 ld = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
444 rd = (prec > digits ? prec - digits : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
445 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
446 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
447 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
448 ld = 1;
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
449 rd = (prec > digits ? prec - 1 : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
450 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
451
27458
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
452 fw = ld + 1 + rd;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
453 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
454
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
455 if (! (rat_format || bank_format || hex_format || bit_format)
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
456 && (print_e || print_g || print_eng
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
457 || 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
458 || 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
459 || ld + rd > (1.5 * prec)))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
460 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
461 if (print_g)
27458
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
462 fmt = float_format (prec, prec);
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
463 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
464 {
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
465 // e+ddd
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
466 int ex = 5;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
467
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
468 if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
469 {
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
470 // -ddd.
27458
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
471 fw = 1 + prec + ex;
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
472 if (inf_or_nan)
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
473 {
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
474 fw = 3;
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
475 ex = 0;
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
476 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
477 fmt = float_format (fw, ex, prec - 1, std::ios::fixed);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
478 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
479 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
480 {
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
481 // -d.
27458
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
482 fw = prec + ex;
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
483 if (inf_or_nan)
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
484 {
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
485 fw = 3;
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
486 ex = 0;
2f4e8dce06da Don't print leading spaces before scalar values in interpeter (bug #56939)
Rik <rik@octave.org>
parents: 27454
diff changeset
487 }
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
488 fmt = float_format (fw, ex, prec - 1, std::ios::scientific);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
489 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
490 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
491 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
492 else if (! bank_format && (inf_or_nan || int_only))
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
493 fmt = float_format (fw, ld);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
494 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
495 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
496
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
497 if (uppercase_format)
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
498 fmt.uppercase ();
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
499
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
500 return float_display_format (fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
501 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
502
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
503 // Works for double and float.
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
504
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
505 template <typename T>
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
506 float_display_format
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
507 make_scalar_format (const T& val)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
508 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
509 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
510 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
511
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
512 bool inf_or_nan = (octave::math::isinf (val) || octave::math::isnan (val));
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
513
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
514 bool int_only = (! inf_or_nan && octave::math::x_nint (val) == val);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
515
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
516 T val_abs = (val < 0 ? -val : val);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
517
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
518 int digits = (inf_or_nan || val_abs == 0) ? 0 : num_digits (val_abs);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
519
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
520 return make_real_format<T> (digits, inf_or_nan, int_only);
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
521 }
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
522
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
523 template <>
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
524 float_display_format
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
525 make_format (const double& d)
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
526 {
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
527 return make_scalar_format (d);
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
528 }
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
529
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
530 template <>
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
531 float_display_format
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
532 make_format (const float& f)
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
533 {
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
534 return make_scalar_format (f);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
535 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
536
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
537 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
538 static inline float_display_format
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
539 make_real_matrix_format (int x_max, int x_min, bool inf_or_nan,
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
540 int int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
541 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
542 T scale = ((x_max == 0 || int_or_inf_or_nan)
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
543 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1)));
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
544
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
545 float_format fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
546
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
547 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
548
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
549 int fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
550
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
551 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
552 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
553 fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
554 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
555 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
556 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
557 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
558 int digits = (x_max > x_min ? x_max : x_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
559 fw = (digits <= 0 ? 5 : digits + 4);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
560 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
561 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
562 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
563 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
564 fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
565 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
566 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
567 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
568 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
569 fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
570 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
571 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
572 else if (Vfixed_point_format && ! print_g)
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
573 {
27453
05f84e5cb08a Display correct number of digits with "format long" and fixed_point_format (bug #56938).
Rik <rik@octave.org>
parents: 27451
diff changeset
574 rd = prec - 1;
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
575 fw = rd + 3;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
576 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
577 fw = 4;
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
578 }
1715
6f4631c7118c [project @ 1996-01-08 07:57:04 by jwe]
jwe
parents: 1658
diff changeset
579 else if (int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
580 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
581 int digits = (x_max > x_min ? x_max : x_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
582 fw = (digits <= 0 ? 2 : digits + 1);
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
583 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
584 fw = 4;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
585 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
586 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
587 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
588 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
589 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
590 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
591 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
592 ld_max = x_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
593 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
594 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
595 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
596 else if (x_max < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
597 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
598 ld_max = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
599 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
600 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
601 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
602 else
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
603 {
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
604 ld_max = 1;
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
605 rd_max = (prec > 1 ? prec - 1 : prec);
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
606 x_max = 1;
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
607 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
608
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
609 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
610 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
611 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
612 ld_min = x_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
613 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
614 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
615 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
616 else if (x_min < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
617 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
618 ld_min = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
619 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
620 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
621 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
622 else
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
623 {
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
624 ld_min = 1;
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
625 rd_min = (prec > 1 ? prec - 1 : prec);
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
626 x_min = 1;
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
627 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
628
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
629 ld = (ld_max > ld_min ? ld_max : ld_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
630 rd = (rd_max > rd_min ? rd_max : rd_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
631
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
632 fw = 1 + ld + 1 + rd;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
633 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
634 fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
635 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
636
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
637 if (! (rat_format || bank_format || hex_format || bit_format)
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
638 && (print_e || print_eng || print_g
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
639 || (! Vfixed_point_format
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
640 && (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
641 || 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
642 || ld + rd > (1.5 * prec)))))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
643 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
644 if (print_g)
27439
251056aeba5d Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents: 27434
diff changeset
645 fmt = float_format (prec+6, prec);
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
646 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
647 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
648 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
649 if (x_max > 100 || x_min > 100)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
650 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
651
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
652 if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
653 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
654 fw = 4 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
655 if (inf_or_nan && fw < 6)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
656 fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
657 fmt = float_format (fw, ex, prec - 1, std::ios::fixed);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
658 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
659 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
660 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
661 fw = 2 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
662 if (inf_or_nan && fw < 4)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
663 fw = 4;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
664 fmt = float_format (fw, prec - 1, std::ios::scientific);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
665 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
666 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
667 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
668 else if (! bank_format && int_or_inf_or_nan)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
669 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
670 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
671 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
672
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
673 if (uppercase_format)
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
674 fmt.uppercase ();
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
675
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
676 return float_display_format (scale, fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
677 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
678
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
679 template <typename MT>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
680 static inline float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
681 make_matrix_format (const MT& m)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
682 {
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30588
diff changeset
683 error_unless (m.ndims () == 2);
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
684
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
685 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
686 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
687
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
688 bool inf_or_nan = m.any_element_is_inf_or_nan ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
689
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
690 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
691
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
692 MT m_abs = m.abs ();
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
693
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
694 typedef typename MT::element_type ELT_T;
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
695
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
696 ELT_T max_abs = pr_max_internal (m_abs);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
697 ELT_T min_abs = pr_min_internal (m_abs);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
698
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
699 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs));
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
700
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
701 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs));
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
702
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
703 return make_real_matrix_format<ELT_T> (x_max, x_min, inf_or_nan,
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
704 int_or_inf_or_nan);
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
705 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
706
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
707 template <>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
708 float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
709 make_format (const Matrix& m)
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
710 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
711 return make_matrix_format (m);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
712 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
713
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
714 template <>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
715 float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
716 make_format (const FloatMatrix& m)
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
717 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
718 return make_matrix_format (m);
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
719 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
720
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
721 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
722 static inline float_display_format
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
723 make_complex_format (int x_max, int x_min, int r_x,
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
724 bool inf_or_nan, int int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
725 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
726 float_format r_fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
727 float_format i_fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
728
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
729 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
730
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
731 int i_fw = 0, r_fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
732
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
733 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
734 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
735 i_fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
736 r_fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
737 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
738 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
739 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
740 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
741 int digits = r_x;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
742 i_fw = 0;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
743 r_fw = (digits <= 0 ? 5 : digits + 4);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
744 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
745 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
746 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
747 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
748 r_fw = 2 * sizeof (T);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
749 i_fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
750 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
751 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
752 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
753 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
754 r_fw = 8 * sizeof (T);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
755 i_fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
756 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
757 }
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
758 else if (int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
759 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
760 int digits = (x_max > x_min ? x_max : x_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
761 i_fw = (digits <= 0 ? 1 : digits);
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
762 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
763 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
764 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
765 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
766 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
767 }
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
768 ld = r_fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
769 }
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
770 else // ordinary case of floating point numeric values
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
771 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
772 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
773 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
774 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
775 ld_max = x_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
776 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
777 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
778 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
779 else if (x_max < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
780 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
781 ld_max = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
782 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
783 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
784 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
785 else
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
786 {
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
787 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
788 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
789 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
790 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
791
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
792 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
793 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
794 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
795 ld_min = x_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
796 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
797 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
798 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
799 else if (x_min < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
800 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
801 ld_min = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
802 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
803 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
804 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
805 else
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
806 {
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
807 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
808 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
809 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
810 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
811
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
812 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
813 rd = (rd_max > rd_min ? rd_max : rd_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
814
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
815 i_fw = ld + 1 + rd;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
816 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
817 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
818 {
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
819 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
820 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
821 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
822 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
823
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
824 if (! (rat_format || bank_format || hex_format || bit_format)
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
825 && (print_e || print_eng || print_g
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
826 || 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
827 || 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
828 || 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
829 || ld + rd > (1.5 * prec)))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
830 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
831 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
832 {
27439
251056aeba5d Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents: 27434
diff changeset
833 int width = prec + 6;
27429
e0134184c1fd Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents: 27277
diff changeset
834 r_fmt = float_format (width, prec);
e0134184c1fd Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents: 27277
diff changeset
835 i_fmt = float_format (width, prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
836 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
837 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
838 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
839 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
840 if (x_max > 100 || x_min > 100)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
841 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
842
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
843 if (print_eng)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
844 {
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21547
diff changeset
845 i_fw = 3 + prec + ex;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
846 r_fw = i_fw + 1;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
847 if (inf_or_nan && i_fw < 5)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
848 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
849 i_fw = 5;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
850 r_fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
851 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
852 r_fmt = float_format (r_fw, ex, prec - 1, std::ios::fixed);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
853 i_fmt = float_format (i_fw, ex, prec - 1, std::ios::fixed);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
854 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
855 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
856 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
857 i_fw = 1 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
858 r_fw = i_fw + 1;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
859 if (inf_or_nan && i_fw < 3)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
860 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
861 i_fw = 3;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
862 r_fw = 4;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
863 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
864 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
865 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
866 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
867 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
868
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
869 if (uppercase_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
870 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
871 r_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
872 i_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
873 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
874 }
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
875 else if (! bank_format && int_only)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
876 {
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
877 r_fmt = float_format (r_fw, ld);
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
878 i_fmt = float_format (i_fw, ld);
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
879 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
880 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
881 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
882 r_fmt = float_format (r_fw, rd, std::ios::fixed);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
883 i_fmt = float_format (i_fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
884 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
885
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
886 return float_display_format (r_fmt, i_fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
887 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
888
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
889 template <typename T>
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
890 float_display_format
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
891 make_complex_scalar_format (const std::complex<T>& c)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
892 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
893 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
894 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
895
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
896 T rp = c.real ();
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
897 T ip = c.imag ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
898
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
899 bool inf_or_nan = (octave::math::isinf (c) || octave::math::isnan (c));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
900
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
901 bool int_only = (octave::math::x_nint (rp) == rp
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
902 && octave::math::x_nint (ip) == ip);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
903
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
904 T r_abs = (rp < 0 ? -rp : rp);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
905 T i_abs = (ip < 0 ? -ip : ip);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
906
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
907 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
908 int i_x = (i_abs == 0 ? 0 : num_digits (i_abs));
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
909
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
910 int x_max, x_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
911
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
912 if (r_x > i_x)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
913 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
914 x_max = r_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
915 x_min = i_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
916 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
917 else
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
918 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
919 x_max = i_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
920 x_min = r_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
921 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
922
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
923 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
924 }
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
925
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
926 template <>
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
927 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
928 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
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 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
931 }
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
932
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
933 template <>
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
934 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
935 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
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 return make_complex_scalar_format (fc);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
938 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
939
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
940 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
941 static inline float_display_format
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
942 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
943 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
944 int int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
945 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
946 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
947 ? 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
948
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
949 float_format r_fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
950 float_format i_fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
951
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
952 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
953
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
954 int i_fw = 0, r_fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
955
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
956 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
957 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
958 i_fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
959 r_fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
960 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
961 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
962 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
963 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
964 int digits = (r_x_max > r_x_min ? r_x_max : r_x_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
965 i_fw = 0;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
966 r_fw = (digits <= 0 ? 5 : digits + 4);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
967 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
968 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
969 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
970 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
971 r_fw = 2 * sizeof (T);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
972 i_fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
973 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
974 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
975 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
976 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
977 r_fw = 8 * sizeof (T);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
978 i_fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
979 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
980 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
981 else if (Vfixed_point_format && ! print_g)
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
982 {
27453
05f84e5cb08a Display correct number of digits with "format long" and fixed_point_format (bug #56938).
Rik <rik@octave.org>
parents: 27451
diff changeset
983 rd = prec - 1;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
984 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
985 r_fw = i_fw + 2;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
986 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
987 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
988 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
989 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
990 }
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
991 }
1715
6f4631c7118c [project @ 1996-01-08 07:57:04 by jwe]
jwe
parents: 1658
diff changeset
992 else if (int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
993 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
994 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
995 i_fw = (digits <= 0 ? 1 : digits);
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
996 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
997 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
998 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
999 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1000 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1001 }
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
1002 rd = r_fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1003 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1004 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1005 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1006 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1007 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1008 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1009 ld_max = x_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1010 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
1011 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1012 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1013 else if (x_max < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1014 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1015 ld_max = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1016 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
1017 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1018 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1019 else
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1020 {
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1021 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
1022 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
1023 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
1024 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1025
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1026 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1027 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1028 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1029 ld_min = x_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1030 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
1031 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1032 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1033 else if (x_min < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1034 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1035 ld_min = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1036 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
1037 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1038 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1039 else
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1040 {
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1041 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
1042 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
1043 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
1044 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1045
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1046 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
1047 rd = (rd_max > rd_min ? rd_max : rd_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1048
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1049 i_fw = ld + 1 + rd;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1050 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1051 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1052 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1053 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1054 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1055 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1056 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1057
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1058 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
1059 && (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
1060 || (! Vfixed_point_format
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
1061 && (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
1062 || 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
1063 || 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
1064 || ld + rd > (1.5 * prec)))))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1065 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1066 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1067 {
27439
251056aeba5d Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents: 27434
diff changeset
1068 int width = prec + 6;
27429
e0134184c1fd Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents: 27277
diff changeset
1069 r_fmt = float_format (width, prec);
e0134184c1fd Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents: 27277
diff changeset
1070 i_fmt = float_format (width, prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1071 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1072 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1073 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1074 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1075 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
1076 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1077
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1078 if (print_eng)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1079 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1080 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
1081 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
1082 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
1083 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1084 i_fw = 5;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1085 r_fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1086 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1087 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
1088 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
1089 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1090 else
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 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
1093 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
1094 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
1095 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1096 i_fw = 3;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1097 r_fw = 4;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1098 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1099 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
1100 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
1101 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1102 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1103
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
1104 if (uppercase_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1105 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1106 r_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1107 i_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1108 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1109 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
1110 else if (! bank_format && int_or_inf_or_nan)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1111 {
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1112 r_fmt = float_format (r_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1113 i_fmt = float_format (i_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1114 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1115 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1116 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1117 r_fmt = float_format (r_fw, rd, std::ios::fixed);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1118 i_fmt = float_format (i_fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1119 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1120
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1121 return float_display_format (scale, r_fmt, i_fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1122 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1123
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1124 template <typename CMT>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1125 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
1126 make_complex_matrix_format (const CMT& cm)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1127 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1128 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1129 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1130
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1131 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
1132 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
1133
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1134 RMT rp = real (cm);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1135 RMT ip = imag (cm);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1136
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1137 bool inf_or_nan = cm.any_element_is_inf_or_nan ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1138
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1139 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
1140 && ip.all_elements_are_int_or_inf_or_nan ());
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1141
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1142 RMT r_m_abs = rp.abs ();
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1143 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
1144 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
1145
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1146 RMT i_m_abs = ip.abs ();
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1147 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
1148 ELT_T i_min_abs = pr_min_internal (i_m_abs);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1149
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
1150 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
1151
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1152 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
1153
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1154 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
1155
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 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
1157
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1158 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
1159 int x_min = (r_x_min > i_x_min ? r_x_min : i_x_min);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1160
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1161 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
1162 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
1163 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1164
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1165 template <>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1166 float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1167 make_format (const ComplexMatrix& cm)
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1168 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1169 return make_complex_matrix_format (cm);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1170 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1171
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1172 template <>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1173 float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1174 make_format (const FloatComplexMatrix& cm)
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1175 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1176 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
1177 }
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1178
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1179 template <>
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1180 float_display_format
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1181 make_format (const boolNDArray&)
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 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
1184 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1185
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1186 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1187 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
1188 make_range_format (int x_max, int x_min, int all_ints)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1189 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1190 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
1191 ? 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
1192
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1193 float_format fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1194
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
1195 int prec = std::min (output_precision (), pr_output_traits<T>::DIGITS10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1196
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
1197 int fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1198
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1199 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1200 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1201 fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1202 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1203 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1204 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1205 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1206 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
1207 fw = (digits < 0 ? 5 : digits + 4);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1208 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1209 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1210 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1211 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1212 fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1213 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1214 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1215 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1216 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1217 fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1218 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1219 }
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1220 else if (all_ints)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1221 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1222 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
1223 fw = digits + 1;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
1224 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1225 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1226 else if (Vfixed_point_format && ! print_g)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1227 {
27453
05f84e5cb08a Display correct number of digits with "format long" and fixed_point_format (bug #56938).
Rik <rik@octave.org>
parents: 27451
diff changeset
1228 rd = prec - 1;
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1229 fw = rd + 3;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1230 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1231 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1232 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1233 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1234 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1235 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1236 ld_max = x_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1237 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
1238 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1239 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1240 else if (x_max < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1241 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1242 ld_max = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1243 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
1244 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1245 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1246 else
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1247 {
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1248 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
1249 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
1250 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
1251 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1252
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1253 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1254 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1255 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1256 ld_min = x_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1257 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
1258 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1259 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1260 else if (x_min < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1261 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1262 ld_min = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1263 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
1264 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1265 }
27451
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1266 else
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1267 {
ce0399fa017a Display only 5 significant digits for "format short" at all times (bug #56936).
Rik <rik@octave.org>
parents: 27439
diff changeset
1268 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
1269 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
1270 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
1271 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1272
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1273 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
1274 rd = (rd_max > rd_min ? rd_max : rd_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1275
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1276 fw = ld + rd + 3;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1277 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1278
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1279 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
1280 && (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
1281 || (! Vfixed_point_format
30216
c2132e0147ff maint: use ALL_CAPS for static const variables used as constants.
Rik <rik@octave.org>
parents: 30001
diff changeset
1282 && (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
1283 || 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
1284 || ld + rd > (1.5 * prec)))))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1285 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1286 if (print_g)
27439
251056aeba5d Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents: 27434
diff changeset
1287 fmt = float_format (prec+6, prec);
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1288 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1289 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1290 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1291 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
1292 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1293
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1294 if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1295 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1296 fw = 5 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1297 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
1298 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1299 else
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 = 3 + 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, 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
1303 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1304 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1305 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
1306 else if (! bank_format && all_ints)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1307 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1308 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1309 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1310
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
1311 if (uppercase_format)
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
1312 fmt.uppercase ();
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
1313
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1314 return float_display_format (scale, fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1315 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1316
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1317 template <>
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1318 float_display_format
28638
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28637
diff changeset
1319 make_format (const octave::range<double>& r)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1320 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1321 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1322 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1323
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1324 double r_min = r.base ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1325 double r_max = r.limit ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1326
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1327 if (r_max < r_min)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1328 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1329 double tmp = r_max;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1330 r_max = r_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1331 r_min = tmp;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1332 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1333
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1334 bool all_ints = r.all_elements_are_ints ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1335
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
1336 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
1337 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
1338
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1339 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
1340
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 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
1342
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1343 return make_range_format<double> (x_max, x_min, all_ints);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1344 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1345
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1346 template <typename T>
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1347 union equiv
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1348 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1349 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
1350 unsigned char i[sizeof (T)];
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1351 };
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1352
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1353 #define PRINT_CHAR_BITS(os, c) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1354 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1355 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1356 unsigned char ctmp = c; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1357 char stmp[9]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1358 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1359 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1360 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1361 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1362 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1363 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1364 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1365 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1366 stmp[8] = '\0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1367 os << stmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1368 } \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1369 while (0)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1370
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1371 #define PRINT_CHAR_BITS_SWAPPED(os, c) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1372 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1373 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1374 unsigned char ctmp = c; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1375 char stmp[9]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1376 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1377 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1378 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1379 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1380 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1381 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1382 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1383 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1384 stmp[8] = '\0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1385 os << stmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1386 } \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1387 while (0)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1388
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
1389 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1390 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
1391 pr_any_float (std::ostream& os, const float_format& fmt, T val)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1392 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1393 // 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
1394 // for hex and bit formats.
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1395 //
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1396 // {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
1397 // {bit,hex}_format == 2: print native
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1398
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
1399 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
1400
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1401 if (hex_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1402 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1403 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
1404
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
1405 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
1406 tmp.val = val;
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1407
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1408 // 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
1409
27462
730af4e7034a Correctly display integer types with format hex (bug #56966).
Rik <rik@octave.org>
parents: 27154
diff changeset
1410 // 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
1411 // 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
1412
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27183
diff changeset
1413 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
1414 = 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
1415
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1416 os.fill ('0');
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
1417 if (uppercase_format)
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
1418 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
1419 else
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
1420 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
1421
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1422 if (hex_format > 1
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1423 || 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
1424 {
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
1425 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
1426 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
1427 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1428 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1429 {
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
1430 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
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 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1434 else if (bit_format)
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1435 {
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
1436 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
1437 tmp.val = val;
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1438
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27183
diff changeset
1439 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
1440 = 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
1441
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1442 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
1443 {
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
1444 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
1445 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
1446 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1447 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1448 {
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1449 if (bit_format > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1450 {
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
1451 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
1452 PRINT_CHAR_BITS (os, tmp.i[i]);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1453 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1454 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1455 {
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
1456 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
1457 PRINT_CHAR_BITS (os, tmp.i[i]);
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 }
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1460 }
27433
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1461 else if (val == 0)
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1462 {
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1463 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
1464
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1465 if (fw > 0)
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1466 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
1467 else
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1468 os << "0";
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1469 }
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1470 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
1471 {
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1472 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
1473
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1474 if (fw > 0)
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1475 os << std::setw (fw) << "NA";
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1476 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1477 os << "NA";
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 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
1480 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
1481 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
1482 {
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1483 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
1484
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1485 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
1486 if (val < 0)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1487 s = "-Inf";
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1488 else
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1489 s = "Inf";
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1490
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1491 if (fw > 0)
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1492 os << std::setw (fw) << s;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1493 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1494 os << s;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1495 }
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
1496 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
1497 {
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1498 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
1499
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1500 if (fw > 0)
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1501 os << std::setw (fw) << "NaN";
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1502 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1503 os << "NaN";
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 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
1506 os << pr_engineering_float<T> (fmt, val);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
1507 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
1508 os << pr_formatted_float<T> (fmt, val);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1509 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1510
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 template <typename T>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1512 static inline void
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1513 pr_float (std::ostream& os, const float_display_format& fmt, T val)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1514 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1515 double scale = fmt.scale_factor ();
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1516
27434
57f5c5768eb3 Disallow exponential format in combination with fixed_point_format.
Rik <rik@octave.org>
parents: 27433
diff changeset
1517 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
1518 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
1519
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1520 pr_any_float (os, fmt.real_format (), val);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1521 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1522
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 template <typename T>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1524 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
1525 pr_imag_float (std::ostream& os, const float_display_format& fmt, T val)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1526 {
27454
43ece0b8318b Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents: 27453
diff changeset
1527 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
1528
43ece0b8318b Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents: 27453
diff changeset
1529 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
1530 val /= scale;
43ece0b8318b Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents: 27453
diff changeset
1531
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1532 pr_any_float (os, fmt.imag_format (), val);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1533 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1534
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
1535 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1536 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
1537 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
1538 const std::complex<T>& cval)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1539 {
27454
43ece0b8318b Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents: 27453
diff changeset
1540 T r = cval.real ();
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1541
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1542 pr_float (os, fmt, r);
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1543
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1544 if (! bank_format)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1545 {
27454
43ece0b8318b Fix display of complex values when fixed_point_format is true (bug #56961).
Rik <rik@octave.org>
parents: 27453
diff changeset
1546 T i = cval.imag ();
4349
a6c22c2c9b09 [project @ 2003-02-21 18:59:07 by jwe]
jwe
parents: 4270
diff changeset
1547 if (! (hex_format || bit_format) && lo_ieee_signbit (i))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1548 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1549 os << " - ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1550 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
1551 pr_imag_float (os, fmt, i);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1552 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1553 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1554 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1555 if (hex_format || bit_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1556 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1557 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1558 os << " + ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1559
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1560 pr_imag_float (os, fmt, i);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1561 }
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
1562 os << 'i';
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1563 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1564 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1565
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1566 static inline void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1567 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
1568 bool pr_as_read_syntax)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1569 {
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30588
diff changeset
1570 error_unless (nr == 0 || nc == 0);
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1571
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1572 if (pr_as_read_syntax)
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1573 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1574 if (nr == 0 && nc == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1575 os << "[]";
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1576 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
1577 os << "zeros (" << nr << ", " << nc << ')';
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1578 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1579 else
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1580 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1581 os << "[]";
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1582
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1583 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
1584 os << '(' << nr << 'x' << nc << ')';
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1585 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1586 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1587
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1588 static inline void
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1589 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
1590 bool pr_as_read_syntax)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1591 {
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30588
diff changeset
1592 error_unless (dims.any_zero ());
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1593
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1594 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
1595 os << "zeros (" << dims.str (',') << ')';
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1596 else
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1597 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1598 os << "[]";
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1599
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1600 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
1601 os << '(' << dims.str () << ')';
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1602 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1603 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1604
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1605 static inline void
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1606 pr_scale_header (std::ostream& os, double scale)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1607 {
27434
57f5c5768eb3 Disallow exponential format in combination with fixed_point_format.
Rik <rik@octave.org>
parents: 27433
diff changeset
1608 if (Vfixed_point_format && ! (print_g || print_e) && scale != 1)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1609 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1610 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
1611
3568
58549b931ad5 [project @ 2000-02-03 10:21:54 by jwe]
jwe
parents: 3548
diff changeset
1612 os << " "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1613 << std::setw (8) << std::setprecision (1)
21662
5b9868c2e212 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21583
diff changeset
1614 << 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
1615 << scale
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
1616 << "*\n";
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1617
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1618 if (! Vcompact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1619 os << "\n";
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1620 }
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1621 }
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1622
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1623 static inline void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1624 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
1625 octave_idx_type lim, octave_idx_type col, int extra_indent)
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1626 {
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1627 if (total_width > max_width && Vsplit_long_rows)
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1628 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1629 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
1630
4833
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
1631 if (col != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1632 {
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1633 if (Vcompact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1634 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1635 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1636 os << "\n\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1637 }
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1638
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1639 octave_idx_type num_cols = lim - col;
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1640
3548
ab7fa5a8f23f [project @ 2000-02-03 01:17:15 by jwe]
jwe
parents: 3538
diff changeset
1641 os << std::setw (extra_indent) << "";
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1642
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1643 if (num_cols == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1644 os << " Column " << col + 1 << ":\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1645 else if (num_cols == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1646 os << " Columns " << col + 1 << " and " << lim << ":\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1647 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1648 os << " Columns " << col + 1 << " through " << lim << ":\n";
2915
649549662cf6 [project @ 1997-04-30 20:51:40 by jwe]
jwe
parents: 2907
diff changeset
1649
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1650 if (! Vcompact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1651 os << "\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1652 }
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1653 }
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1654
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
1655 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1656 static inline void
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1657 pr_plus_format (std::ostream& os, const T& val)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1658 {
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1659 if (val > T (0))
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1660 os << plus_format_chars[0];
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1661 else if (val < T (0))
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1662 os << plus_format_chars[1];
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1663 else
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1664 os << plus_format_chars[2];
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1665 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1666
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
1667 // 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
1668 //
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1669 // 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
1670 //
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1671 // 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
1672
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1673 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1674 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
1675 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
1676 {
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 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
1678 }
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1679
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 #define INSTANTIATE_ABS(T) \
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1681 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
1682
25569
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1683 INSTANTIATE_ABS(int8_t);
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1684 INSTANTIATE_ABS(int16_t);
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1685 INSTANTIATE_ABS(int32_t);
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1686 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
1687
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1688 #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
1689 template <> \
25569
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1690 inline T \
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1691 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
1692 { \
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1693 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
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
25569
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1696 SPECIALIZE_UABS(uint8_t)
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1697 SPECIALIZE_UABS(uint16_t)
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1698 SPECIALIZE_UABS(uint32_t)
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1699 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
1700
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1701 #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
1702 template <> \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1703 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
1704 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
1705 { \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1706 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
1707 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
1708 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1709 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
1710 { \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1711 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
1712 = 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
1713 (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
1714 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1715 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
1716 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
1717 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1718 if (! isneg) \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1719 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
1720 } \
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 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
1723 }
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1724
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1725 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
1726 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
1727 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
1728 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
1729 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
1730 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
1731 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
1732 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
1733
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1734 #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
1735 template <> \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1736 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
1737 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
1738 { \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1739 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
1740 int digits \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1741 = 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
1742 (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
1743 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1744 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
1745 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1746 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
1747 }
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1748
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1749 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
1750 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
1751 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
1752 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
1753 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
1754 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
1755 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
1756 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
1757
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1758 void
24760
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1759 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
1760 bool d, bool pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1761 {
24760
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1762 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
1763 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1764
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
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, 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
1767 {
24760
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1768 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
1769 }
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1770
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1771 void
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1772 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
1773 char, bool)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1774 {
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1775 panic_impossible ();
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1776 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1777
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1778 void
24668
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
1779 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
1780 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
1781 {
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1782 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
1783 os << d;
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1784 else if (plus_format)
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1785 pr_plus_format (os, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1786 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1787 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1788 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1789 os << d;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1790 else
24668
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
1791 pr_float (os, fmt, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1792 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1793 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1794
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1795 void
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1796 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
1797 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
1798 {
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1799 if (pr_as_read_syntax)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1800 os << d;
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1801 else if (plus_format)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1802 pr_plus_format (os, d);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1803 else
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1804 {
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1805 if (free_format)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1806 os << d;
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1807 else
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1808 pr_float (os, fmt, d);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1809 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1810 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1811
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1812 template <typename MT>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1813 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
1814 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
1815 {
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1816 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
1817 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
1818
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1819 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
1820 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
1821
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1822 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
1823 {
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1824 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
1825 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
1826
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1827 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
1828 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
1829 }
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1830
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1831 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
1832 os << ']';
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
24781
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1835 template <typename MT>
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1836 static inline void
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1837 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
1838 {
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1839 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
1840 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
1841
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1842 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
1843 {
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1844 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
1845 {
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1846 octave_quit ();
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1847
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30329
diff changeset
1848 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
1849 }
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 if (i < nr - 1)
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1852 os << "\n";
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1853 }
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1854 }
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1855
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1856 static inline int
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1857 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
1858 {
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
1859 int r_fw = fmt.real_format().width ();
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
1860 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
1861
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1862 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
1863
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1864 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
1865 retval += 5;
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1866
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1867 return retval;
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
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1870 template <typename MT>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1871 static void
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1872 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
1873 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1874 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1875 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1876 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1877
2408
e22aae3ccfad [project @ 1996-10-15 16:37:52 by jwe]
jwe
parents: 2387
diff changeset
1878 if (nr == 0 || nc == 0)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1879 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1880 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
1881 pr_plus_format_matrix (os, m);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1882 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1883 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1884 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
1885 int column_width = get_column_width (fmt);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1886 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
1887 octave_idx_type max_width = octave::command_editor::terminal_cols ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1888
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1889 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1890 max_width -= 4;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1891 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1892 max_width -= extra_indent;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1893
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1894 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1895 max_width = 0;
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1896
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1897 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1898 {
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1899 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
1900 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1901 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1902
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1903 octave_idx_type inc = nc;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1904 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
1905 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1906 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1907 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1908 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1909 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1910
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1911 if (pr_as_read_syntax)
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 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
1914 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1915 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1916 while (col < nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1917 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1918 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
1919
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1920 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
1921 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1922 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1923
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1924 if (i == 0 && j == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1925 os << "[ ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1926 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1927 {
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
1928 if (j > col)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1929 os << ", ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1930 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1931 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1932 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1933
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30329
diff changeset
1934 pr_float (os, fmt, m(i, j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1935 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1936
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1937 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1938
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1939 if (col >= nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1940 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1941 if (i == nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1942 os << " ]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1943 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1944 os << ";\n";
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 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1947 os << " ...\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1948 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1949 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1950 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1951 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1952 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1953 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
1954
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1955 pr_scale_header (os, fmt.scale_factor ());
10315
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 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
1958 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
1959 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
1960
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1961 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
1962 extra_indent);
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 i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1965 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1966 os << std::setw (extra_indent) << "";
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 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
1969 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1970 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1971
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1972 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1973
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30329
diff changeset
1974 pr_float (os, fmt, m(i, j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1975 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1976
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1977 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1978 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1979 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1980 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1981 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1982 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1983 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1984
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1985 template <typename DMT>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1986 static void
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1987 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
1988 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1989 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1990 octave_idx_type nr = m.rows ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1991 octave_idx_type nc = m.columns ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1992
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1993 if (nr == 0 || nc == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1994 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
1995 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
1996 pr_plus_format_matrix (os, m);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1997 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1998 {
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1999 float_display_format fmt
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
2000 = 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
2001 int column_width = get_column_width (fmt);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2002 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
2003 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
2004
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2005 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2006 max_width -= 4;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2007 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2008 max_width -= extra_indent;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2009
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2010 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2011 max_width = 0;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2012
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2013 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2014 {
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
2015 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
2016 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2017 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2018
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2019 octave_idx_type inc = nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2020 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
2021 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2022 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2023 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2024 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2025 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2026
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2027 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2028 {
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2029 os << "diag (";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2030
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2031 octave_idx_type col = 0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2032 while (col < nc)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2033 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
2034 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
2035
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2036 for (octave_idx_type j = col; j < lim; j++)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2037 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
2038 octave_quit ();
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2039
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2040 if (j == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2041 os << "[ ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2042 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2043 {
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
2044 if (j > col)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2045 os << ", ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2046 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2047 os << " ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2048 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2049
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30329
diff changeset
2050 pr_float (os, fmt, m(j, j));
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2051 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2052
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2053 col += inc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2054
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2055 if (col >= nc)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2056 os << " ]";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2057 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2058 os << " ...\n";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2059 }
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2060 os << ')';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2061 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2062 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2063 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
2064 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
2065
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2066 os << "Diagonal Matrix\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2067 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2068 os << "\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2069
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
2070 pr_scale_header (os, fmt.scale_factor ());
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2071
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21748
diff changeset
2072 // kluge. Get the true width of a number.
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2073 int zero_fw;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2074 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2075 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
2076 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
2077 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
2078 zero_fw = tmp_oss.str ().length ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2079 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2080
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2081 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
2082 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
2083 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
2084
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2085 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
2086 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2087
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2088 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
2089 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2090 os << std::setw (extra_indent) << "";
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 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
2093 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2094 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2095
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2096 os << " ";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2097
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2098 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
2099 pr_float (os, fmt, m(i, j));
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2100 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2101 os << std::setw (zero_fw) << '0';
10315
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2104 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2105 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2106 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2107 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2108 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2109 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2110 }
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2111
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2112 template <typename NDA_T, typename ELT_T, typename MAT_T>
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
2113 void print_nd_array (std::ostream& os, const NDA_T& nda,
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
2114 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
2115 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2116
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23565
diff changeset
2117 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
2118 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
2119 else
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2120 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2121
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2122 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
2123
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2124 dim_vector dims = nda.dims ();
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2125
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2126 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
2127
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2128 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
2129
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2130 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
2131 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
2132
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2133 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
2134 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
2135
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2136 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
2137 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2138 octave_quit ();
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2139
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2140 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
2141
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2142 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
2143 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2144 nm += "(:,:,";
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 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
2147
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2148 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
2149 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2150 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
2151
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2152 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
2153 buf << ',';
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2154 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2155 buf << ')';
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2156 }
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 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
2159 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2160
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
2161 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
2162
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
2163 idx(0) = octave::idx_vector (':');
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
2164 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
2165
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2166 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
2167 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
2168
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2169 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
2170 = 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
2171
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2172 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
2173 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2174 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
2175 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2176 else
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2177 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2178 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
2179 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
2180 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2181
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
2182 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
2183 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2184 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2185 }
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
2186
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2187 void
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2188 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
2189 bool pr_as_read_syntax, int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2190 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2191 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2192 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2193 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2194 case 2:
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19318
diff changeset
2195 octave_print_internal (os, Matrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2196 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2197 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2198
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2199 default:
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2200 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2201 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2202 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2203 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2204
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2205 void
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2206 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
2207 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
2208 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2209 switch (nda.ndims ())
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2210 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2211 case 1:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2212 case 2:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2213 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
2214 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
2215 break;
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 default:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2218 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
2219 break;
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2220 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2221 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2222
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2223 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2224 static inline void
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2225 pr_plus_format (std::ostream& os, const std::complex<T>& c)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2226 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2227 T rp = c.real ();
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2228 T ip = c.imag ();
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2229
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
2230 if (rp == 0)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2231 {
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
2232 if (ip == 0)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2233 os << ' ';
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2234 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2235 os << 'i';
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2236 }
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
2237 else if (ip == 0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
2238 pr_plus_format (os, rp);
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2239 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2240 os << 'c';
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2241 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2242
24668
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
2243 extern void
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
2244 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
2245 const Complex& c, bool pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2246 {
17867
49d573a1deda avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
2247 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
2248 os << c;
49d573a1deda avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
2249 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
2250 pr_plus_format (os, c);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2251 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2252 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2253 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2254 os << c;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2255 else
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2256 pr_float (os, fmt, c);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2257 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2258 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2259
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2260 void
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2261 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
2262 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
2263 {
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2264 if (pr_as_read_syntax)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2265 os << c;
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2266 else if (plus_format)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2267 pr_plus_format (os, c);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2268 else
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2269 {
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2270 if (free_format)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2271 os << c;
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2272 else
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2273 pr_float (os, fmt, c);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2274 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2275 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2276
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2277 void
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2278 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
2279 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
2280 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2281 octave_idx_type nr = m.rows ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2282 octave_idx_type nc = m.columns ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2283
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2284 if (nr == 0 || nc == 0)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2285 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
2286 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
2287 pr_plus_format_matrix (os, m);
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2288 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2289 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2290 int fw = 2;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2291 int column_width = fw + 2;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2292 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
2293 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
2294
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2295 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2296 max_width -= 4;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2297 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2298 max_width -= extra_indent;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2299
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2300 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2301 max_width = 0;
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 (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2304 {
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
2305 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
2306 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2307 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2308
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2309 octave_idx_type inc = nc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2310 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
2311 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2312 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2313 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2314 inc++;
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 if (pr_as_read_syntax)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2318 {
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18816
diff changeset
2319 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
2320
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2321 os << "eye (";
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18816
diff changeset
2322 os << ":, ";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2323
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2324 octave_idx_type col = 0;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2325 while (col < nc)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2326 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
2327 octave_idx_type lim = (col + inc < nc ? col + inc : nc);
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 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
2330 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
2331 octave_quit ();
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2332
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2333 if (j == 0)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2334 os << "[ ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2335 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2336 {
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
2337 if (j > col)
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2338 os << ", ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2339 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2340 os << " ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2341 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2342
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2343 os << pvec (j);
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2344 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2345
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2346 col += inc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2347
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2348 if (col >= nc)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2349 os << " ]";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2350 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2351 os << " ...\n";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2352 }
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2353 os << ')';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2354 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2355 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2356 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
2357 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
2358
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2359 os << "Permutation Matrix\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2360 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2361 os << "\n";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2362
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2363 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
2364 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
2365 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
2366
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2367 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
2368 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2369
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2370 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
2371 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2372 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2373
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2374 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
2375 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2376 octave_quit ();
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 os << " ";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2379
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30329
diff changeset
2380 os << std::setw (fw) << m(i, j);
10315
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2383 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2384 os << "\n";
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2387 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2388 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2389 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2390
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2391 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2392 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
2393 bool pr_as_read_syntax, int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2394 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2395 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2396 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2397 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2398 case 2:
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19318
diff changeset
2399 octave_print_internal (os, ComplexMatrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2400 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2401 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2402
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2403 default:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2404 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
2405 (os, nda, pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2406 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2407 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2408 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2409
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2410 void
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2411 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
2412 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
2413 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2414 switch (nda.ndims ())
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2415 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2416 case 1:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2417 case 2:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2418 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
2419 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
2420 break;
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 default:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2423 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
2424 (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
2425 break;
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2426 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2427 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2428
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2429 // 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
2430
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2431 void
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2432 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
2433 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
2434 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2435 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
2436 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2437
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2438 void
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2439 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
2440 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
2441 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2442 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
2443 }
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 void
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2446 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
2447 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
2448 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2449 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
2450 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2451
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2452 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2453 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
2454 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
2455 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2456 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
2457 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2458
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2459 void
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2460 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
2461 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
2462 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2463 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
2464 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2465
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2466 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2467 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
2468 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
2469 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2470 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
2471 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2472
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2473 void
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2474 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
2475 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
2476 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2477 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
2478 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2479
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2480 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2481 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
2482 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2483 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2484 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
2485 }
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 void
28638
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28637
diff changeset
2488 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
2489 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2490 {
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2491 double base = r.base ();
28636
a3db48e66ef8 use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents: 28028
diff changeset
2492 double increment = r.increment ();
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2493 double limit = r.limit ();
28637
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
2494 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
2495 octave_idx_type num_elem = r.numel ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2496
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2497 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
2498 pr_plus_format_matrix (os, r);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2499 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2500 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
2501 float_display_format fmt = make_format (r);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2502
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2503 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2504 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2505 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2506 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2507 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
2508 if (increment != 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2509 os << increment << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2510 os << limit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2511 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2512 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2513 {
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
2514 pr_float (os, fmt, base);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2515 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
2516 if (increment != 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2517 {
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
2518 pr_float (os, fmt, increment);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2519 os << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2520 }
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
2521 pr_float (os, fmt, limit);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2522 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2523 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2524 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2525 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
2526 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
2527
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2528 int column_width = get_column_width (fmt);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2529 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
2530 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
2531
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2532 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2533 {
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
2534 os << ' ';
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
2535 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
2536 os << ' ' << r.elem (i);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2537 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2538 }
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 octave_idx_type inc = num_elem;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2541 if (total_width > max_width && Vsplit_long_rows)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2542 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2543 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2544 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2545 inc++;
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 max_width -= extra_indent;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2549
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2550 if (max_width < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2551 max_width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2552
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
2553 pr_scale_header (os, fmt.scale_factor ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2554
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2555 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2556 while (col < num_elem)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2557 {
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2558 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
2559 : num_elem);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2560
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2561 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
2562 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2563
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2564 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2565
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2566 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
2567 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2568 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2569
16169
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2570 double val;
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2571 if (i == 0)
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2572 val = base;
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2573 else
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2574 val = base + i * increment;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2575
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2576 if (i == num_elem - 1)
28637
fb37f50d5ba8 new Range::final_value function
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
2577 val = final_value;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2578
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2579 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2580
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
2581 pr_float (os, fmt, val);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2582 }
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 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2585 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2586 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2587 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2588 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2589
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2590 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2591 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
2592 bool pr_as_read_syntax,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2593 int extra_indent)
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2594 {
21583
d5963a6e29c2 Use integer output formatting for logicals (bug #47607)
Mike Miller <mtmiller@octave.org>
parents: 21568
diff changeset
2595 uint8NDArray tmp (bm);
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2596 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent);
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2597 }
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2598
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2599 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2600 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
2601 bool pr_as_read_syntax,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2602 int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2603 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2604 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2605 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2606 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2607 case 2:
19317
25f535b90e52 Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.
Carnë Draug <carandraug@octave.org>
parents: 19255
diff changeset
2608 octave_print_internal (os, boolMatrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2609 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2610 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2611
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2612 default:
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2613 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
2614 boolMatrix> (os, nda, pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2615 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2616 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2617 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2618
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2619 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2620 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
2621 bool pr_as_read_syntax,
21066
258c787cd9ce maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents: 20946
diff changeset
2622 int /* FIXME: extra_indent */,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2623 bool pr_as_string)
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2624 {
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2625 if (pr_as_string)
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2626 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2627 octave_idx_type nstr = chm.rows ();
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2628
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2629 if (pr_as_read_syntax && nstr > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2630 os << "[ ";
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2631
2907
8bb31a2b480b [project @ 1997-04-30 05:01:46 by jwe]
jwe
parents: 2903
diff changeset
2632 if (nstr != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2633 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2634 for (octave_idx_type i = 0; i < nstr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2635 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2636 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2637
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2638 std::string row = chm.row_as_string (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2639
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2640 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2641 {
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25569
diff changeset
2642 os << '"' << octave::undo_string_escapes (row) << '"';
10315
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 if (i < nstr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2645 os << "; ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2646 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2647 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2648 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2649 os << row;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2650
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2651 if (i < nstr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2652 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2653 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2654 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2655 }
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2656
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2657 if (pr_as_read_syntax && nstr > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2658 os << " ]";
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2659 }
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2660 else
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2661 {
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2662 os << "sorry, printing char matrices not implemented yet\n";
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2663 }
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2664 }
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2665
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2666 void
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2667 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
2668 bool pr_as_read_syntax, int extra_indent,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2669 bool pr_as_string)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2670 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2671 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2672 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2673 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2674 case 2:
19318
6c9ea5be96bf Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents: 19317
diff changeset
2675 octave_print_internal (os, charMatrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2676 pr_as_read_syntax, extra_indent, pr_as_string);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2677 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2678
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2679 default:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2680 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
2681 pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2682 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2683 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2684 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2685
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2686 void
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2687 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
2688 bool pr_as_read_syntax, int extra_indent)
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2689 {
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9643
diff changeset
2690 Array<std::string> nda (dim_vector (1, 1), s);
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2691
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2692 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent);
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2693 }
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2694
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2695 void
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9643
diff changeset
2696 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
2697 bool pr_as_read_syntax, int /* extra_indent */)
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2698 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2699 // 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
2700 // function. Can fix this with std::is_same from C++11.
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2701
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23565
diff changeset
2702 if (nda.isempty ())
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2703 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
2704 else if (nda.numel () == 1)
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2705 {
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2706 os << nda(0);
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2707 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2708 else
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2709 {
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2710 int ndims = nda.ndims ();
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2711
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2712 dim_vector dims = nda.dims ();
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2713
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2714 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2715
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2716 octave_idx_type m = 1;
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2717
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2718 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2719 m *= dims(i);
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2720
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2721 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2722 octave_idx_type nc = dims(1);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2723
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2724 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
2725 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2726 std::string nm = "ans";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2727
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2728 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2729 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2730 nm += "(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2731
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2732 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2733
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2734 for (int k = 2; k < ndims; k++)
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 buf << ra_idx(k) + 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 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
2739 buf << ',';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2740 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2741 buf << ')';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2742 }
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 nm += buf.str ();
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
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
2747 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
2748
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
2749 idx(0) = octave::idx_vector (':');
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
2750 idx(1) = octave::idx_vector (':');
10315
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 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
2753 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
2754
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2755 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
2756
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2757 // 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
2758 // in neatly aligned columns...
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 octave_idx_type n_rows = page.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2761 octave_idx_type n_cols = page.cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2762
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2763 os << nm << " =\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2764 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2765 os << "\n";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2766
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2767 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
2768 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2769 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
2770 os << " " << page(ii, jj);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2771
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2772 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2773 }
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 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2776 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2777
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
2778 increment_index (ra_idx, dims, 2);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2779 }
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2780 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2781 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2782
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2783 template <typename T>
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2784 class
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2785 octave_print_conv
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2786 {
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2787 public:
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2788 typedef T print_conv_type;
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2789 };
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2790
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2791 #define PRINT_CONV(T1, T2) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2792 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2793 class \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2794 octave_print_conv<T1> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2795 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2796 public: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2797 typedef T2 print_conv_type; \
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2798 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2799
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2800 PRINT_CONV (octave_int8, octave_int16);
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2801 PRINT_CONV (octave_uint8, octave_uint16);
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2802
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2803 #undef PRINT_CONV
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2804
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2805 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2806 static inline void
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2807 pr_int (std::ostream& os, const T& d, int fw = 0)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2808 {
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
2809 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
2810 const unsigned char *tmpi = d.iptr ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2811
5544
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2812 // Unless explicitly asked for, always print in big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2813 // format for hex and bit formats.
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2814 //
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2815 // {bit,hex}_format == 1: print big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2816 // {bit,hex}_format == 2: print native
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2817
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2818 if (hex_format)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2819 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
2820 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
2821
27462
730af4e7034a Correctly display integer types with format hex (bug #56966).
Rik <rik@octave.org>
parents: 27154
diff changeset
2822 os.fill ('0');
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
2823 if (uppercase_format)
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
2824 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
2825 else
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
2826 os.flags (std::ios::right | std::ios::hex);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2827
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
2828 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
2829 {
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
2830 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
2831 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
2832 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2833 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2834 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2835 for (int i = sz - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2836 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
2837 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2838 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2839 else if (bit_format)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2840 {
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
2841 if (octave::mach_info::words_big_endian ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2842 {
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
2843 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
2844 PRINT_CHAR_BITS (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2845 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2846 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2847 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2848 if (bit_format > 1)
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++)
31919
dd23a26b7294 pr-output.cc: Fix integer output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31907
diff changeset
2851 PRINT_CHAR_BITS (os, tmpi[i]);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2852 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2853 else
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 for (int i = sz - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2856 PRINT_CHAR_BITS (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2857 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2858 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2859 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2860 else
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2861 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
2862 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
2863
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2864 os << std::setw (fw)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2865 << typename octave_print_conv<T>::print_conv_type (d);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2866
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2867 if (bank_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2868 os << ".00";
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2869 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2870 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2871
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2872 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2873 pr_int (std::ostream&, const octave_int8&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2874
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2875 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2876 pr_int (std::ostream&, const octave_int16&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2877
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2878 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2879 pr_int (std::ostream&, const octave_int32&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2880
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2881 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2882 pr_int (std::ostream&, const octave_int64&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2883
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2884 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2885 pr_int (std::ostream&, const octave_uint8&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2886
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2887 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2888 pr_int (std::ostream&, const octave_uint16&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2889
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2890 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2891 pr_int (std::ostream&, const octave_uint32&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2892
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2893 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2894 pr_int (std::ostream&, const octave_uint64&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2895
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2896 template <typename T>
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2897 void
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2898 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
2899 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
2900 const octave_int<T>& val, bool)
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2901 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2902 if (plus_format)
24781
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
2903 pr_plus_format (os, val);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2904 else
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2905 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2906 if (free_format)
23534
b6498c088fca maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents: 23457
diff changeset
2907 os << typename octave_print_conv<octave_int<T>>::print_conv_type (val);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2908 else
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2909 {
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2910 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
2911
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
2912 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
2913 }
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2914 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2915 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2916
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2917 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \
30583
d4e559fcf88f pr-output.cc: Remove redundant visibility specifications.
Gene Harvey <gharveymn@gmail.com>
parents: 30565
diff changeset
2918 void \
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2919 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
2920 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
2921 const octave_int<TYPE>& val, bool dummy) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2922 { \
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2923 octave_print_internal_template (os, fmt, val, dummy); \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2924 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2925
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2926 PRINT_INT_SCALAR_INTERNAL (int8_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2927 PRINT_INT_SCALAR_INTERNAL (uint8_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2928 PRINT_INT_SCALAR_INTERNAL (int16_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2929 PRINT_INT_SCALAR_INTERNAL (uint16_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2930 PRINT_INT_SCALAR_INTERNAL (int32_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2931 PRINT_INT_SCALAR_INTERNAL (uint32_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2932 PRINT_INT_SCALAR_INTERNAL (int64_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2933 PRINT_INT_SCALAR_INTERNAL (uint64_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2934
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2935 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2936 static inline void
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2937 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
2938 bool pr_as_read_syntax, int extra_indent)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2939 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2940 // 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
2941 // function. Can fix this with std::is_same from C++11.
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2942
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23565
diff changeset
2943 if (nda.isempty ())
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2944 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
2945 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
2946 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
2947 pr_as_read_syntax);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2948 else if (plus_format && ! pr_as_read_syntax)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2949 {
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2950 int ndims = nda.ndims ();
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2951
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2952 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2953
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2954 dim_vector dims = nda.dims ();
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2955
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2956 octave_idx_type m = 1;
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2957
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2958 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2959 m *= dims(i);
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2960
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2961 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2962 octave_idx_type nc = dims(1);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2963
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2964 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
2965 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2966 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2967 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2968 std::string nm = "ans(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2969
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2970 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2971
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2972 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2973 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2974 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2975
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2976 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
2977 buf << ',';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2978 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2979 buf << ')';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2980 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2981
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2982 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2983
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2984 os << nm << " =\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2985 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2986 os << "\n";
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
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
2989 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
2990
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
2991 idx(0) = octave::idx_vector (':');
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
2992 idx(1) = octave::idx_vector (':');
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2993
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2994 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
2995 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
2996
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2997 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
2998
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2999 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
3000 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3001 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
3002 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3003 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3004
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30329
diff changeset
3005 pr_plus_format (os, page(ii, jj));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3006 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3007
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3008 if ((ii < nr - 1) || (i < m -1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3009 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3010 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3011
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3012 if (i < m - 1)
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 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3015 increment_index (ra_idx, dims, 2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3016 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3017 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3018 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3019 else
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3020 {
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3021 int ndims = nda.ndims ();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3022
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3023 dim_vector dims = nda.dims ();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3024
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3025 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3026
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3027 octave_idx_type m = 1;
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3028
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3029 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3030 m *= dims(i);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3031
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3032 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3033 octave_idx_type nc = dims(1);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3034
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3035 int fw = 0;
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3036 if (hex_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3037 fw = 2 * nda(0).byte_size ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3038 else if (bit_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3039 fw = nda(0).nbits ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3040 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3041 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3042 bool isneg = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3043 int digits = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3044
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3045 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
3046 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3047 int new_digits
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3048 = 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
3049 (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
3050
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3051 if (new_digits > digits)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3052 digits = new_digits;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3053
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3054 if (! isneg)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3055 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
3056 }
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 fw = digits + isneg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3059 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3060
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3061 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2));
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3062 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
3063 int max_width = octave::command_editor::terminal_cols () - extra_indent;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3064 octave_idx_type inc = nc;
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3065 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
3066 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3067 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3068 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3069 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3070 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3071
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3072 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
3073 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3074 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3075 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3076 std::string nm = "ans(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3077
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3078 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3079
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3080 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3081 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3082 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3083
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3084 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
3085 buf << ',';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3086 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
3087 buf << ')';
10315
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3090 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3091
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3092 os << nm << " =\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3093 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3094 os << "\n";
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
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
3097 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
3098
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
3099 idx(0) = octave::idx_vector (':');
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29494
diff changeset
3100 idx(1) = octave::idx_vector (':');
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3101
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3102 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
3103 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
3104
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3105 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
3106
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3107 if (free_format)
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 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3110 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3111
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3112 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
3113 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3114 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
3115 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3116 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3117 os << " ";
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
3118 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
3119 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3120 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3121 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3122
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3123 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
3124 os << ']';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3125 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3126 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3127 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
3128 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
3129
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3130 octave_idx_type n_rows = page.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3131 octave_idx_type n_cols = page.cols ();
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 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
3134 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
3135 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
3136 : n_cols);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3137
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3138 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
3139 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3140
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3141 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
3142 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3143 os << std::setw (extra_indent) << "";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3144
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3145 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
3146 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3147 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3148 os << " ";
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30329
diff changeset
3149 pr_int (os, page(ii, jj), fw);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3150 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3151 if ((ii < n_rows - 1) || (i < m -1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3152 os << "\n";
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3155 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3156
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3157 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3158 {
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 increment_index (ra_idx, dims, 2);
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 }
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3163 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3164 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3165
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3166 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3167 OCTINTERP_API void \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3168 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
3169 bool pr_as_read_syntax, int extra_indent) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3170 { \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3171 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3172 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3173
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3174 PRINT_INT_ARRAY_INTERNAL (octave_int8)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3175 PRINT_INT_ARRAY_INTERNAL (octave_uint8)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3176 PRINT_INT_ARRAY_INTERNAL (octave_int16)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3177 PRINT_INT_ARRAY_INTERNAL (octave_uint16)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3178 PRINT_INT_ARRAY_INTERNAL (octave_int32)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3179 PRINT_INT_ARRAY_INTERNAL (octave_uint32)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3180 PRINT_INT_ARRAY_INTERNAL (octave_int64)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3181 PRINT_INT_ARRAY_INTERNAL (octave_uint64)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3182
8012
63dbb85452cc fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents: 7896
diff changeset
3183 void
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
3184 octave_print_internal (std::ostream&, const Cell&, bool, int, bool)
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3185 {
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
3186 panic_impossible ();
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3187 }
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3188
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3189 void
19620
a1d172bfcb2f eliminate some unused variable and typedef warnings
John W. Eaton <jwe@octave.org>
parents: 19367
diff changeset
3190 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
3191 {
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3192 panic_impossible ();
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3193 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3194
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31375
diff changeset
3195 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
3196
20915
a3359fe50966 remove unused nargout variables
John W. Eaton <jwe@octave.org>
parents: 20909
diff changeset
3197 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
3198 doc: /* -*- texinfo -*-
27154
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3199 @deftypefn {} {@var{s} =} rats (@var{x})
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3200 @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
3201 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
3202
27154
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3203 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
3204 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
3205 @code{@var{x} = @var{N}/@var{D}}.
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3206
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3207 The optional second argument defines the maximum length of the string
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3208 representing the elements of @var{x}. By default, @var{len} is 9.
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3209
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3210 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
3211 @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
3212
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3213 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
3214
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3215 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3216 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3217 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
3218 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
3219 @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
3220 @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
3221
27154
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3222 @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
3223 @end deftypefn */)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3224 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3225 int nargin = args.length ();
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3226
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20897
diff changeset
3227 if (nargin < 1 || nargin > 2)
7896
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3228 print_usage ();
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3229
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3230 octave_value arg = args(0);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3231
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23577
diff changeset
3232 if (! arg.isnumeric ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3233 error ("rats: X must be numeric");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3234
27477
b470734a025e Return an empty string from rats when input is empty (bug #57004).
Rik <rik@octave.org>
parents: 27476
diff changeset
3235 if (arg.isempty ())
b470734a025e Return an empty string from rats when input is empty (bug #57004).
Rik <rik@octave.org>
parents: 27476
diff changeset
3236 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
3237
27476
b8b1bf5b2bbf Reshape N-D arrays to 2-D arrays within rats() (bug #57003).
Rik <rik@octave.org>
parents: 27475
diff changeset
3238 // 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
3239 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
3240 {
b8b1bf5b2bbf Reshape N-D arrays to 2-D arrays within rats() (bug #57003).
Rik <rik@octave.org>
parents: 27475
diff changeset
3241 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
3242 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
3243 }
b8b1bf5b2bbf Reshape N-D arrays to 2-D arrays within rats() (bug #57003).
Rik <rik@octave.org>
parents: 27475
diff changeset
3244
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3245 unwind_protect frame;
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3246
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3247 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
3248
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3249 rat_string_len = 9;
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3250 if (nargin == 2)
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3251 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
3252
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3253 frame.protect_var (rat_format);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3254
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3255 rat_format = true;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3256
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3257 std::ostringstream buf;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3258 arg.print (buf);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3259 std::string s = buf.str ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3260
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3261 std::list<std::string> lst;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3262
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
3263 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
3264 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
3265
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3266 while (n < s_len)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3267 {
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
3268 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
3269
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3270 if (m == std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3271 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3272 lst.push_back (s.substr (n));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3273 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3274 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3275 else
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 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
3278 n = m + 1;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3279 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3280 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3281
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3282 return ovl (string_vector (lst));
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3283 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3284
26111
3e44ed9d50b6 Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26009
diff changeset
3285 /*
28011
b31a118729ed update bug status for tests
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3286 %!test <*56941>
26716
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3287 %! [old_fmt, old_spacing] = format ();
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3288 %! unwind_protect
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3289 %! format short;
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3290 %! assert (rats (-2.0005, 10), "-4001/2000");
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3291 %! assert (strtrim (rats (2.0005, 30)), "4001/2000");
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3292 %! 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
3293 %! 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
3294 %! unwind_protect_cleanup
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3295 %! format (old_fmt);
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3296 %! format (old_spacing);
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3297 %! 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
3298
28011
b31a118729ed update bug status for tests
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3299 %!test <*57003>
27476
b8b1bf5b2bbf Reshape N-D arrays to 2-D arrays within rats() (bug #57003).
Rik <rik@octave.org>
parents: 27475
diff changeset
3300 %! 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
3301 %! 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
3302 %! 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
3303 %! 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
3304 %! 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
3305
28011
b31a118729ed update bug status for tests
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3306 %!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
3307
29494
76269aa97398 if bug number is supplied, prefer '%!test' over '%!xtest'
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3308 %!test <57704>
28028
79b583e31590 Segregate remaining failing rats() tests in to BIST test for bug #57704.
Rik <rik@octave.org>
parents: 28011
diff changeset
3309 %! [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
3310 %! unwind_protect
79b583e31590 Segregate remaining failing rats() tests in to BIST test for bug #57704.
Rik <rik@octave.org>
parents: 28011
diff changeset
3311 %! format short;
79b583e31590 Segregate remaining failing rats() tests in to BIST test for bug #57704.
Rik <rik@octave.org>
parents: 28011
diff changeset
3312 %! 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
3313 %! 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
3314 %! unwind_protect_cleanup
79b583e31590 Segregate remaining failing rats() tests in to BIST test for bug #57704.
Rik <rik@octave.org>
parents: 28011
diff changeset
3315 %! format (old_fmt);
79b583e31590 Segregate remaining failing rats() tests in to BIST test for bug #57704.
Rik <rik@octave.org>
parents: 28011
diff changeset
3316 %! format (old_spacing);
79b583e31590 Segregate remaining failing rats() tests in to BIST test for bug #57704.
Rik <rik@octave.org>
parents: 28011
diff changeset
3317 %! end_unwind_protect
79b583e31590 Segregate remaining failing rats() tests in to BIST test for bug #57704.
Rik <rik@octave.org>
parents: 28011
diff changeset
3318
26111
3e44ed9d50b6 Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26009
diff changeset
3319 */
3e44ed9d50b6 Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26009
diff changeset
3320
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3321 DEFUN (disp, args, nargout,
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3322 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
3323 doc: /* -*- texinfo -*-
24764
36ca11f78553 Document second calling form of disp().
Rik <rik@octave.org>
parents: 23219
diff changeset
3324 @deftypefn {} {} disp (@var{x})
36ca11f78553 Document second calling form of disp().
Rik <rik@octave.org>
parents: 23219
diff changeset
3325 @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
3326 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
3327
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3328 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
3329
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3330 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3331 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3332 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
3333
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3334 @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
3335 @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
3336 @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
3337 @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
3338
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3339 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3340 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
3341
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3342 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
3343 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
3344 @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
3345 @end deftypefn */)
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3346 {
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20897
diff changeset
3347 if (args.length () != 1)
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3348 print_usage ();
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3349
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3350 octave_value_list retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3351
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3352 octave_value arg = args(0);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3353
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3354 if (nargout == 0)
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3355 arg.print (octave_stdout);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3356 else
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3357 {
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3358 std::ostringstream buf;
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3359 arg.print (buf);
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
3360 retval = (octave_value (buf.str (), arg.is_dq_string () ? '"' : '\''));
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3361 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3362
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3363 return retval;
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3364 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3365
23738
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3366 DEFMETHOD (fdisp, interp, args, ,
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3367 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
3368 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
3369 @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
3370 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
3371
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3372 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
3373
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3374 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3375 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3376 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
3377
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3378 @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
3379 @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
3380 @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
3381 @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
3382
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3383 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3384 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
3385 @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
3386 @end deftypefn */)
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3387 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20801
diff changeset
3388 if (args.length () != 2)
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3389 print_usage ();
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3390
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3391 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
3392
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3393 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
3394
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3395 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
3396
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
3397 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
3398
30890
ac478fdded94 Ffdisp: Place validation/error code before normal code.
Rik <rik@octave.org>
parents: 30723
diff changeset
3399 if (! osp)
ac478fdded94 Ffdisp: Place validation/error code before normal code.
Rik <rik@octave.org>
parents: 30723
diff changeset
3400 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
3401
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3402 octave_value arg = args(1);
30890
ac478fdded94 Ffdisp: Place validation/error code before normal code.
Rik <rik@octave.org>
parents: 30723
diff changeset
3403 arg.print (*osp);
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3404
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
3405 return ovl ();
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3406 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3407
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3408 /*
25108
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3409 ## FIXME: This test writes values to a file, but then never checks them.
9629
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3410 %!test
25108
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3411 %! [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
3412 %! unwind_protect
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3413 %! format short
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3414 %! fd = tmpfile ();
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3415 %! 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
3416 %! 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
3417 %! 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
3418 %! endfor
9629
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3419 %! endfor
25108
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3420 %! fclose (fd);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3421 %! 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
3422 %! 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
3423 %! 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
3424 %! end_unwind_protect
13129
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3425
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3426 %!test
25108
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3427 %! [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
3428 %! unwind_protect
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3429 %! 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
3430 %! 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
3431 %! 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
3432 %! 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
3433 %! 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
3434 %! 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
3435 %! format loose;
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3436 %! 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
3437 %! format compact;
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3438 %! 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
3439 %! 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
3440 %! 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
3441 %! endfor
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3442 %! 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
3443 %! 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
3444 %! 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
3445 %! end_unwind_protect
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3446 */
9629
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3447
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3448 DEFUN (display, args, ,
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3449 classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3450 doc: /* -*- texinfo -*-
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23564
diff changeset
3451 @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
3452 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
3453
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3454 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
3455 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
3456 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
3457
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3458 @example
23182
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3459 myclass (@dots{})
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3460 @end example
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3461
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3462 Or:
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3463
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3464 @example
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3465 myobj = myclass (@dots{})
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3466 @end example
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3467
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
3468 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
3469 avoid the default output:
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3470
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3471 @example
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3472 @group
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3473 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
3474 @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
3475
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 <class myclass>
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3477 @end group
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3478 @end example
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3479
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
3480 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
3481 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
3482 @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
3483
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3484 @seealso{disp, class, subsref, subsasgn}
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3485 @end deftypefn */)
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3486 {
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3487 int nargin = args.length ();
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3488
23332
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3489 // 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
3490 // 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
3491 // 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
3492 // 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
3493
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3494 if (nargin < 1 || nargin > 2)
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3495 print_usage ();
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3496
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3497 std::string name;
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3498
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3499 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
3500 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
3501 else
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3502 {
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3503 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
3504 name = names(0);
22898
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
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 // 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
3508 // object type.
22898
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 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
3511
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3512 // 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
3513 // disp is done.
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3514
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3515 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
3516 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
3517 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
3518
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3519 // 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
3520
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3521 feval ("disp", ovl (value));
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3522
22989
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3523 if (print_newlines)
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3524 octave_stdout << std::endl;
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 return ovl ();
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3527 }
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3528
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3529 /*
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3530 %!test
26585
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3531 %! [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
3532 %! unwind_protect
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3533 %! format short;
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3534 %! 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
3535 %! 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
3536 %! 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
3537 %! 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
3538 %! 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
3539 %! end_unwind_protect
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3540
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3541 %!test
26585
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3542 %! [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
3543 %! unwind_protect
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3544 %! format short;
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3545 %! 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
3546 %! 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
3547 %! 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
3548 %! 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
3549 %! 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
3550 %! end_unwind_protect
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3551
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3552 ## Test input validation
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3553 %!error display ()
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3554 %!error display (1,2)
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3555 */
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3556
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
3557 static inline void
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3558 init_format_state (void)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3559 {
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3560 free_format = false;
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3561 plus_format = false;
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3562 rat_format = false;
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3563 bank_format = false;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
3564 hex_format = 0;
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
3565 bit_format = 0;
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3566 print_e = false;
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3567 print_g = false;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3568 print_eng = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3569 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3570
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3571 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
3572
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
3573 static inline void
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3574 set_format_style (int argc, const string_vector& argv)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3575 {
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3576 if (--argc == 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3577 {
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3578 // Special case of no options, reset to default values
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3579 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
3580 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
3581 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
3582 Vcompact_format = false;
27499
2545345f8bd9 Set format to lowercase when called with no arguments.
Rik <rik@octave.org>
parents: 27491
diff changeset
3583 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
3584 return;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3585 }
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3586
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3587 int idx = 1;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3588 std::string format;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3589
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3590 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
3591
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3592 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
3593 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
3594 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
3595 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
3596 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
3597 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
3598 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
3599 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
3600 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
3601 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
3602 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
3603 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
3604 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
3605 int prec = output_precision ();
28851
1ac5a76ae91d use [=] capture default specification where possible
John W. Eaton <jwe@octave.org>
parents: 28638
diff changeset
3606 frame.add ([=] (void) { 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
3607
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3608 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
3609 while (argc-- > 0)
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3610 {
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3611 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
3612 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
3613
30992
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3614 if (arg == "default")
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3615 {
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3616 format = "short";
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3617 init_format_state ();
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3618 set_output_prec (5);
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3619 Vcompact_format = false;
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3620 uppercase_format = false;
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3621 }
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3622 else if (arg == "short")
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3623 {
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3624 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3625 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3626 if (argc > 0)
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3627 {
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3628 arg = argv[idx];
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3629 if (arg == "e")
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 print_e = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3632 format.append (arg);
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3633 argc--; idx++;
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 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
3636 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3637 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3638 print_g = 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++;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3641 }
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 == "eng")
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3643 {
27518
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_eng = 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++;
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3648 }
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3649 }
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3650 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
3651 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3652 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
3653 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3654 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3655 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3656 print_e = true;
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 == "shortg")
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_g = 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 == "shorteng")
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_eng = 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 == "long")
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 if (argc > 0)
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3678 {
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3679 arg = argv[idx];
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3680
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3681 if (arg == "e")
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3682 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3683 print_e = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3684 format.append (arg);
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3685 argc--; idx++;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3686 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3687 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
3688 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3689 print_g = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3690 format.append (arg);
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3691 argc--; idx++;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3692 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3693 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
3694 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3695 print_eng = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3696 format.append (arg);
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3697 argc--; idx++;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3698 }
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3699 }
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3700 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
3701 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3702 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
3703 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3704 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3705 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3706 print_e = true;
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 == "longg")
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_g = 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 == "longeng")
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_eng = 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 == "hex")
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 hex_format = 1;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3728 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3729 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
3730 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3731 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3732 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3733 hex_format = 2;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3734 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3735 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
3736 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3737 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3738 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3739 bit_format = 1;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3740 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3741 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
3742 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3743 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3744 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3745 bit_format = 2;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3746 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3747 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
3748 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3749 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3750 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3751 plus_format = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3752 if (argc > 0)
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3753 {
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3754 arg = argv[idx];
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 if (arg.length () == 3)
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3757 {
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3758 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
3759 format.append (arg);
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3760 argc--; idx++;
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3761 }
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3762 else
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3763 plus_format_chars = "+- ";
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3764 }
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3765 else
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3766 plus_format_chars = "+- ";
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3767 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3768 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
3769 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3770 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3771 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3772 rat_format = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3773 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3774 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
3775 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3776 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3777 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3778 bank_format = true;
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3779 }
27518
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3780 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
3781 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3782 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3783 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3784 free_format = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3785 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3786 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
3787 {
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3788 format = arg;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3789 init_format_state ();
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3790 free_format = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3791 }
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3792 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
3793 Vcompact_format = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3794 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
3795 Vcompact_format = false;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3796 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
3797 uppercase_format = false;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3798 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
3799 uppercase_format = true;
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3800 else
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3801 error ("format: unrecognized format state '%s'", arg.c_str ());
27500
1ef42010c53b Allow multiple arguments to format().
Rik <rik@octave.org>
parents: 27499
diff changeset
3802 }
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3803
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3804 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
3805
25479159213b Don't change anything if format() fails during parsing of multiple arguments.
Rik <rik@octave.org>
parents: 27500
diff changeset
3806 // 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
3807 frame.discard ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3808 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3809
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3810 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
3811 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
3812 @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
3813 @deftypefnx {} {} format options
30992
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3814 @deftypefnx {} {} format (@var{options})
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
3815 @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
3816 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
3817 normal echoing mechanism.
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3818
31660
ccbf38427774 doc: Note interaction between format and output_precision (bug #39832)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 31607
diff changeset
3819 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
3820 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
3821 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
3822 @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
3823 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
3824 @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
3825
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3826 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
3827 (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
3828 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
3829 @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
3830
27521
37f9eb2c05e0 doc: improve format() docstring and NEWS announcement.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27518
diff changeset
3831 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
3832 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
3833
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3834 @table @code
30992
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3835 @item default
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
3836 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
3837
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3838 @item short
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3839 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
3840
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3841 @item long
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3842 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
3843
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3844 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
3845 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
3846
31008
4d74446020ad doc: Document contracted format arguments (bug #62417).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
3847 @item shorte
4d74446020ad doc: Document contracted format arguments (bug #62417).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
3848 @itemx longe
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3849 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
3850 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
3851 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
3852 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
3853 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
3854 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
3855
4d74446020ad doc: Document contracted format arguments (bug #62417).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
3856 @item shortg
4d74446020ad doc: Document contracted format arguments (bug #62417).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
3857 @itemx longg
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3858 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
3859 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
3860 @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
3861
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3862 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3863 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3864 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3865
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3866 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
3867 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
3868 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
3869 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
3870 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
3871 @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
3872 @end example
31375
96f751f8392c doc: grammar check documentation ahead of 8.1 release.
Rik <rik@octave.org>
parents: 31009
diff changeset
3873
31008
4d74446020ad doc: Document contracted format arguments (bug #62417).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
3874 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
3875
4d74446020ad doc: Document contracted format arguments (bug #62417).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
3876 @item shorteng
4d74446020ad doc: Document contracted format arguments (bug #62417).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
3877 @itemx longeng
4d74446020ad doc: Document contracted format arguments (bug #62417).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
3878 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
3879 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
3880 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
3881 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
3882
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3883 @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
3884 @itemx none
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3885 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
3886 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
3887 @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
3888 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
3889 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
3890 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
3891 @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
3892 @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
3893
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3894 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
3895 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
3896
24771
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3897 @table @asis
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3898 @item @qcode{"+"}
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3899 @itemx @qcode{"+"} @qcode{"@var{chars}"}
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3900 @itemx @code{plus}
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3901 @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
3902 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
3903 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
3904 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
3905 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
3906 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
3907
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3908 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
3909 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
3910 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
3911 @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
3912
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3913 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3914 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3915 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3916
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3917 +.-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3918 -.+
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3919 @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
3920 @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
3921
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3922 @item bank
24771
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3923 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
3924 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
3925 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
3926
31907
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3927 @item bit
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3928 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
3929 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
3930
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3931 @example
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3932 @group
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3933 0 10000000000 1001001000011111101101010100010001000010110100011000
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3934 @end group
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3935 @end example
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3936
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3937 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
3938 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
3939 @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
3940 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
3941
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3942 @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
3943 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
3944 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
3945 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
3946 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
3947 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
3948
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3949 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
3950
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3951 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3952 @group
31907
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3953 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
3954 @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
3955 @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
3956
31907
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3957 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
3958 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
3959
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3960 @item hex
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3961 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
3962 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
3963
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3964 @example
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3965 @group
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3966 400921fb54442d18
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3967 @end group
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3968 @end example
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3969
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3970 @item native-hex
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3971 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
3972 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
3973 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
3974
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3975 @example
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3976 @group
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3977 182d4454fb210940
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3978 @end group
d4d3098a15dc pr-output.cc: Fix output for `format native-bit` (bug #63940)
Arun Giridhar <arungiridhar@gmail.com>
parents: 31706
diff changeset
3979 @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
3980
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3981 @item rat
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3982 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
3983 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
3984 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
3985 @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
3986
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
3987 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
3988
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
3989 @table @code
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
3990 @item lowercase (default)
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
3991 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
3992 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
3993
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
3994 @item uppercase
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
3995 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
3996 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
3997 @end table
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
3998
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3999 The 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
4000
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4001 @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
4002 @item compact
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4003 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
4004 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
4005
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4006 @item loose (default)
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4007 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
4008 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
4009 @end table
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4010
27522
3912e3a74e31 doc: Use "rightmost" to describe how format() behaves with multiple arguments.
Rik <rik@octave.org>
parents: 27521
diff changeset
4011 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
4012 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
4013 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
4014
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4015 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
4016 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
4017 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
4018
30329
81d26e8481a6 maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30216
diff changeset
4019 @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
4020 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
4021 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
4022 {
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4023 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
4024
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4025 int nargin = args.length ();
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4026
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4027 if (nargout == 0)
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4028 {
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4029 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
4030
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4031 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
4032
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4033 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
4034 }
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4035 else
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4036 {
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4037 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
4038 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
4039
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4040 if (nargout >= 3)
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4041 retval(2) = (uppercase_format ? "uppercase" : "lowercase");
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4042
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4043 if (nargout >= 2)
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
4044 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
4045
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4046 retval(0) = format_string;
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4047 }
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4048
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4049 return retval;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
4050 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
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 /*
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4053 %!test
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4054 %! [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
4055 %! unwind_protect
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4056 %! ## Test one of the formats
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4057 %! format long e;
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4058 %! format uppercase;
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4059 %! str = disp (pi);
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4060 %! 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
4061 %! str = disp (single (pi));
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4062 %! 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
4063 %! new_fmt = format ();
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4064 %! assert (new_fmt, "longe");
30992
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
4065 %! ## 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
4066 %! format compact;
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4067 %! [~, new_spacing] = format ();
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4068 %! assert (new_spacing, "compact");
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4069 %! format;
27499
2545345f8bd9 Set format to lowercase when called with no arguments.
Rik <rik@octave.org>
parents: 27491
diff changeset
4070 %! [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
4071 %! assert (new_fmt, "short");
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4072 %! assert (new_spacing, "loose");
27499
2545345f8bd9 Set format to lowercase when called with no arguments.
Rik <rik@octave.org>
parents: 27491
diff changeset
4073 %! assert (new_case, "lowercase");
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 #2)
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
4075 %! format compact uppercase long e;
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
4076 %! [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
4077 %! assert (new_fmt, "longe");
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
4078 %! assert (new_spacing, "compact");
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
4079 %! assert (new_case, "uppercase");
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
4080 %! format ("default");
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
4081 %! [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
4082 %! assert (new_fmt, "short");
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
4083 %! assert (new_spacing, "loose");
4ef25c610433 format: Add 'default' format option (bug #62430)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30890
diff changeset
4084 %! 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
4085 %! unwind_protect_cleanup
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4086 %! format (old_fmt);
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4087 %! format (old_spacing);
27491
bea2823affa4 Add new options "uppercase", "lowercase" to format() command.
Rik <rik@octave.org>
parents: 27483
diff changeset
4088 %! format (old_uppercase);
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4089 %! 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
4090
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4091 %!test <*53427>
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4092 %! [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
4093 %! unwind_protect
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4094 %! 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
4095 %! 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
4096 %! 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
4097 %! [fmt, spacing] = format ();
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4098 %! assert (fmt, "long");
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4099 %! assert (spacing, "compact");
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4100 %! unwind_protect_cleanup
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4101 %! format (old_fmt);
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4102 %! format (old_spacing);
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4103 %! end_unwind_protect
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4104
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4105 ## Test input validation
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4106 %!test
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
4107 %! 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
4108
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
4109 */
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4110
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4111 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
4112 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
4113 @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
4114 @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
4115 @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
4116 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
4117 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
4118
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4119 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
4120 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
4121 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
4122
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4123 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4124 @group
26205
cf037b842a9f doc: Clarify example code in fixed_point_format documentation (bug #55208).
Rik <rik@octave.org>
parents: 26111
diff changeset
4125 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
4126 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
4127 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4128
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4129 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
4130
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4131 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
4132 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
4133 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
4134 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
4135 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
4136 @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
4137 @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
4138
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4139 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4140 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
4141 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
4142 @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
4143
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4144 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
4145 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
4146 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
4147 @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
4148 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4149 {
30001
428cccc75cc9 move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
4150 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
4151 "fixed_point_format");
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4152 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4153
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4154 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
4155 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
4156 @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
4157 @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
4158 @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
4159 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
4160 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
4161
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4162 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
4163
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4164 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4165 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
4166 @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
4167
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4168 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4169 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
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 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4172 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
4173 @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
4174
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4175 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
4176 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
4177 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
4178 @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
4179 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4180 {
30001
428cccc75cc9 move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
4181 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
4182 "print_empty_dimensions");
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4183 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4184
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4185 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
4186 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
4187 @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
4188 @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
4189 @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
4190 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
4191 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
4192
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4193 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
4194 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
4195 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
4196 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
4197
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4198 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4199 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4200 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
4201 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4202
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4203 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
4204
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4205 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
4206 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
4207
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4208 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
4209
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4210 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
4211 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
4212 @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
4213 @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
4214
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4215 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
4216 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
4217 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
4218 @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
4219 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4220 {
30001
428cccc75cc9 move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
4221 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
4222 "split_long_rows");
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4223 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
4224
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31375
diff changeset
4225 OCTAVE_END_NAMESPACE(octave)