annotate libinterp/corefcn/pr-output.cc @ 24764:36ca11f78553 stable

Document second calling form of disp(). * pr-output.cc (Fdisp): Document second calling form where string is returned.
author Rik <rik@octave.org>
date Thu, 15 Feb 2018 11:41:56 -0800
parents 3ac9f9ecfae5
children 7b8a3f503575
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1993-2017 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
10 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
19 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21662
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
24 # include "config.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1343
diff changeset
27 #include <cfloat>
2825
60ae49e1284f [project @ 1997-03-25 23:17:36 by jwe]
jwe
parents: 2804
diff changeset
28 #include <cstdio>
1346
9e41dbb74bca [project @ 1995-09-05 06:37:49 by jwe]
jwe
parents: 1343
diff changeset
29 #include <cstring>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
30
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3373
diff changeset
31 #include <iomanip>
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3373
diff changeset
32 #include <iostream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5759
diff changeset
33 #include <sstream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1716
diff changeset
34 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1716
diff changeset
35
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
36 #include "Array-util.h"
453
393e95f46b51 [project @ 1994-06-06 00:05:20 by jwe]
jwe
parents: 296
diff changeset
37 #include "CMatrix.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
38 #include "Range.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
39 #include "cmd-edit.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
40 #include "dMatrix.h"
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2847
diff changeset
41 #include "lo-mappers.h"
7231
2eb392d058bb [project @ 2007-11-30 18:53:29 by jwe]
jwe
parents: 7215
diff changeset
42 #include "lo-math.h"
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
43 #include "mach-info.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1588
diff changeset
44 #include "oct-cmplx.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4051
diff changeset
45 #include "quit.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
46 #include "str-vec.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
47
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
48 #include "Cell.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
49 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
50 #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
51 #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
52 #include "ovl.h"
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
53 #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
54 #include "octave-preserve-stream-state.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
55 #include "pager.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
56 #include "pr-output.h"
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
57 #include "sysdep.h"
6803
fe19c6cb5bc6 [project @ 2007-07-26 18:04:05 by jwe]
jwe
parents: 6788
diff changeset
58 #include "unwind-prot.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
59 #include "utils.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
60 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
61
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
62 // TRUE means use a scaled fixed point format for 'format long' and
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
63 // 'format short'.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
64 static bool Vfixed_point_format = false;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
65
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
66 // The maximum field width for a number printed by the default output
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
67 // routines.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
68 static int Voutput_max_field_width = 10;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
69
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
70 // The precision of the numbers printed by the default output
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
71 // routines.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
72 static int Voutput_precision = 5;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
73
5360
33adb987c033 [project @ 2005-05-23 16:19:56 by jwe]
jwe
parents: 5331
diff changeset
74 // 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
75 // like this: x = [](2x0).
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
76 bool Vprint_empty_dimensions = true;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
77
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
78 // 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
79 // smaller slices that fit on the screen.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
80 static bool Vsplit_long_rows = true;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
81
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
82 // TRUE means don't do any fancy formatting.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
83 static bool free_format = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
84
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
85 // 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
86 static bool plus_format = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
87
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
88 // 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
89 static std::string plus_format_chars = "+- ";
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
90
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
91 // TRUE means always print in a rational approximation
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
92 static bool rat_format = false;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
93
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
94 // 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
95 static int rat_string_len = -1;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
96
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
97 // TRUE means always print like dollars and cents.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
98 static bool bank_format = false;
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
99
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
100 // TRUE means print data in hexadecimal format.
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
101 static int hex_format = 0;
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
102
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
103 // 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
104 static int bit_format = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
105
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
106 // 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
107 bool Vcompact_format = false;
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
108
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
109 // TRUE means use an e format.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
110 static bool print_e = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
111
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
112 // TRUE means use a g format.
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
113 static bool print_g = false;
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
114
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
115 // TRUE means print E instead of e for exponent field.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
116 static bool print_big_e = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
117
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
118 // 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
119 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
120
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
121 class pr_engineering_float;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
122 class pr_formatted_float;
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
123 class pr_rational_float;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
124
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
125 static int
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
126 current_output_max_field_width (void)
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
127 {
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
128 return Voutput_max_field_width;
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
129 }
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
130
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
131 static int
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
132 current_output_precision (void)
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
133 {
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
134 return Voutput_precision;
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
135 }
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
136
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
137 class
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
138 float_format
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
139 {
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
140 public:
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
141
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
142 float_format (int w = current_output_max_field_width (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
143 int p = current_output_precision (), int f = 0)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
144 : fw (w), ex (0), prec (p), fmt (f), up (0), sp (0) { }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
145
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
146 float_format (int w, int e, int p, int f)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
147 : fw (w), ex (e), prec (p), fmt (f), up (0), sp (0) { }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
148
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
149 float_format (const float_format& ff)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
150 : fw (ff.fw), ex (ff.ex), prec (ff.prec), fmt (ff.fmt), up (ff.up),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
151 sp (ff.sp) { }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
152
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
153 float_format& operator = (const float_format& ff)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
154 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
155 if (&ff != this)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
156 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
157 fw = ff.fw;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
158 ex = ff.ex;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
159 prec = ff.prec;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
160 fmt = ff.fmt;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
161 up = ff.up;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
162 sp = ff.sp;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
163 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
164
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
165 return *this;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
166 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
167
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
168 ~float_format (void) { }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
169
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
170 float_format& scientific (void) { fmt = std::ios::scientific; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
171 float_format& fixed (void) { fmt = std::ios::fixed; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
172 float_format& general (void) { fmt = 0; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
173
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
174 float_format& uppercase (void) { up = std::ios::uppercase; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
175 float_format& lowercase (void) { up = 0; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
176
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
177 float_format& precision (int p) { prec = p; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
178
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
179 float_format& width (int w) { fw = w; return *this; }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
180
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
181 float_format& trailing_zeros (bool tz = true)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
182 { sp = tz ? std::ios::showpoint : 0; return *this; }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
183
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
184 friend std::ostream& operator << (std::ostream& os,
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
185 const pr_engineering_float& pef);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
186
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
187 friend std::ostream& operator << (std::ostream& os,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
188 const pr_formatted_float& pff);
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
189
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
190 friend std::ostream& operator << (std::ostream& os,
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
191 const pr_rational_float& prf);
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
192
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
193 private:
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
194
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
195 // Field width. Zero means as wide as necessary.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
196 int fw;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
197
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
198 // Exponent Field width. Zero means as wide as necessary.
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
199 int ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
200
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
201 // Precision.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
202 int prec;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
203
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
204 // Format.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
205 int fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
206
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
207 // E or e.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
208 int up;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
209
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
210 // Show trailing zeros.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
211 int sp;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
212 };
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
213
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
214 static int
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
215 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
216 {
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
217 if (! print_eng)
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
218 return x;
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
219 else
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
220 return x - 3*static_cast<int> (x/3);
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
221
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
222 // The expression above is equivalent to x - (x % 3).
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
223
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
224 // 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
225 // 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
226 // 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
227 // to avoid portability issues, we re-implement the modulo function to
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
228 // the desired behavior (truncation). There may be a gnulib
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
229 // replacement.
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
230
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
231 // 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
232 // 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
233 // 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
234 // 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
235 // 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
236 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
237
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
238 static int
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
239 engineering_exponent (const double& x)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
240 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
241 int ex = 0;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
242 if (x != 0)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
243 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
244 double absval = (x < 0.0 ? -x : x);
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
245 int logabsval = static_cast<int> (std::floor (log10 (absval)));
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
246 // Avoid using modulo function with negative arguments for
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
247 // portability. See extended comment at calc_scale_exp
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
248 if (logabsval < 0.0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
249 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
250 else
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
251 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
252 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
253 return ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
254 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
255
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
256 static int
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
257 num_digits (const double& x)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
258 {
11450
5eb10763069f substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents: 10987
diff changeset
259 return 1 + (print_eng
5eb10763069f substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents: 10987
diff changeset
260 ? engineering_exponent (x)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
261 : 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
262 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
263
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
264 class
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
265 pr_engineering_float
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
266 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
267 public:
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
268
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
269 const float_format& f;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
270
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
271 double val;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
272
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
273 int exponent (void) const
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
274 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
275 return engineering_exponent (val);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
276 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
277
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
278 double mantissa (void) const
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
279 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
280 return val / std::pow (10.0, exponent ());
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
281 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
282
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
283 pr_engineering_float (const float_format& f_arg, double val_arg)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
284 : f (f_arg), val (val_arg) { }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
285 };
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
286
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
287 std::ostream&
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
288 operator << (std::ostream& os, const pr_engineering_float& pef)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
289 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
290 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
291
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
292 if (pef.f.fw >= 0)
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
293 os << std::setw (pef.f.fw - pef.f.ex);
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
294
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
295 if (pef.f.prec >= 0)
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
296 os << std::setprecision (pef.f.prec);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
297
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
298 os.flags (static_cast<std::ios::fmtflags>
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
299 (pef.f.fmt | pef.f.up | pef.f.sp));
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
300
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
301 os << pef.mantissa ();
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
302
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
303 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
304 if (ex < 0)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
305 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
306 os << std::setw (0) << "e-";
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
307 ex = -ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
308 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
309 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
310 os << std::setw (0) << "e+";
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
311
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
312 os << std::setw (pef.f.ex - 2) << std::setfill ('0') << ex;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
313
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
314 return os;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
315 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
316
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
317 class
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
318 pr_formatted_float
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
319 {
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
320 public:
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
321
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
322 const float_format& f;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
323
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
324 double val;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
325
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
326 pr_formatted_float (const float_format& f_arg, double val_arg)
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
327 : f (f_arg), val (val_arg) { }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
328 };
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
329
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
330 std::ostream&
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
331 operator << (std::ostream& os, const pr_formatted_float& pff)
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
332 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
333 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
334
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
335 if (pff.f.fw >= 0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
336 os << std::setw (pff.f.fw);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
337
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
338 if (pff.f.prec >= 0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
339 os << std::setprecision (pff.f.prec);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
340
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
341 os.flags (static_cast<std::ios::fmtflags>
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
342 (pff.f.fmt | pff.f.up | pff.f.sp));
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
343
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
344 os << pff.val;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
345
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
346 return os;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
347 }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
348
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
349 static inline std::string
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
350 rational_approx (double val, int len)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
351 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
352 std::string s;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
353
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
354 if (len <= 0)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
355 len = 10;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
356
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
357 if (octave::math::isinf (val))
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
358 s = "1/0";
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
359 else if (octave::math::isnan (val))
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
360 s = "0/0";
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
361 else if (val < std::numeric_limits<int>::min ()
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
362 || val > std::numeric_limits<int>::max ()
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
363 || octave::math::x_nint (val) == val)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
364 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
365 std::ostringstream buf;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
366 buf.flags (std::ios::fixed);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
367 buf << std::setprecision (0) << octave::math::round (val);
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
368 s = buf.str ();
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
369 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
370 else
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
371 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
372 double lastn = 1.;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
373 double lastd = 0.;
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
374 double n = octave::math::round (val);
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
375 double d = 1.;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
376 double frac = val - n;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
377 int m = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
378
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
379 std::ostringstream buf2;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
380 buf2.flags (std::ios::fixed);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
381 buf2 << std::setprecision (0) << static_cast<int>(n);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
382 s = buf2.str ();
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
383
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
384 while (1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
385 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
386 double flip = 1. / frac;
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
387 double step = octave::math::round (flip);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
388 double nextn = n;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
389 double nextd = d;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
390
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
391 // Have we converged to 1/intmax ?
21747
61f3575250e4 rats: Fix round-off corner case for 32-bit systems (bug #47964)
Mike Miller <mtmiller@octave.org>
parents: 21743
diff changeset
392 if (std::abs (flip) > static_cast<double> (std::numeric_limits<int>::max ()))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
393 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
394 lastn = n;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
395 lastd = d;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
396 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
397 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
398
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
399 frac = flip - step;
20230
e914b5399c67 Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents: 20228
diff changeset
400 n = step * n + lastn;
e914b5399c67 Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents: 20228
diff changeset
401 d = step * d + lastd;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
402 lastn = nextn;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
403 lastd = nextd;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
404
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
405 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
406 buf.flags (std::ios::fixed);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
407 buf << std::setprecision (0) << static_cast<int>(n)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
408 << "/" << static_cast<int>(d);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
409 m++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
410
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
411 if (n < 0 && d < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
412 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
413 // Double negative, string can be two characters longer..
19363
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
414 if (buf.str ().length () > static_cast<unsigned int>(len + 2))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
415 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
416 }
19363
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
417 else if (buf.str ().length () > static_cast<unsigned int>(len))
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
418 break;
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
419
21747
61f3575250e4 rats: Fix round-off corner case for 32-bit systems (bug #47964)
Mike Miller <mtmiller@octave.org>
parents: 21743
diff changeset
420 if (std::abs (n) > std::numeric_limits<int>::max ()
61f3575250e4 rats: Fix round-off corner case for 32-bit systems (bug #47964)
Mike Miller <mtmiller@octave.org>
parents: 21743
diff changeset
421 || std::abs (d) > std::numeric_limits<int>::max ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
422 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
423
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
424 s = buf.str ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
425 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
426
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
427 if (lastd < 0.)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
428 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
429 // Move sign to the top
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
430 lastd = - lastd;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
431 lastn = - lastn;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
432 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
433 buf.flags (std::ios::fixed);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
434 buf << std::setprecision (0) << static_cast<int>(lastn)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
435 << "/" << static_cast<int>(lastd);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
436 s = buf.str ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
437 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
438 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
439
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
440 return s;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
441 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
442
19363
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
443 /*
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
444 %!assert (rats (2.0005, 9), "4001/2000")
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
445 %!assert (rats (-2.0005, 10), "-4001/2000")
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
446 %!assert (strtrim (rats (2.0005, 30)), "4001/2000")
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
447 %!assert (pi - str2num (rats (pi, 30)), 0, 4 * eps)
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
448 %!assert (e - str2num (rats (e, 30)), 0, 4 * eps)
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
449 %!assert (rats (123, 2), " *")
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
450
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
451 %!test
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
452 %! v = 1 / double (intmax);
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
453 %! err = v - str2num (rats(v, 12));
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
454 %! assert (err, 0, 4 * eps);
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
455 */
c490eac28bbb pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
456
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
457 class
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
458 pr_rational_float
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
459 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
460 public:
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
461
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
462 const float_format& f;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
463
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
464 double val;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
465
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
466 pr_rational_float (const float_format& f_arg, double val_arg)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
467 : f (f_arg), val (val_arg) { }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
468 };
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
469
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
470 std::ostream&
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
471 operator << (std::ostream& os, const pr_rational_float& prf)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
472 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
473 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
474
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
475 int fw = (rat_string_len > 0 ? rat_string_len : prf.f.fw);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
476 std::string s = rational_approx (prf.val, fw);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
477
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
478 if (fw >= 0)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
479 os << std::setw (fw);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
480
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
481 os.flags (static_cast<std::ios::fmtflags>
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
482 (prf.f.fmt | prf.f.up | prf.f.sp));
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
483
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
484 if (fw > 0 && s.length () > static_cast<unsigned int>(fw))
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
485 os << "*";
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
486 else
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
487 os << s;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
488
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
489 return os;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
490 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
491
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
492 // Current format for real numbers and the real part of complex
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
493 // numbers.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
494 static float_format *curr_real_fmt = 0;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
495
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
496 // Current format for the imaginary part of complex numbers.
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
497 static float_format *curr_imag_fmt = 0;
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
498
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
499 static double
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
500 pr_max_internal (const Matrix& m)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
501 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
502 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
503 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
504
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
505 double result = -std::numeric_limits<double>::max ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
506
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
507 bool all_inf_or_nan = true;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
508
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
509 for (octave_idx_type j = 0; j < nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
510 for (octave_idx_type i = 0; i < nr; i++)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
511 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
512 double val = m(i,j);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
513 if (! octave::math::finite (val))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
514 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
515
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
516 all_inf_or_nan = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
517
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
518 if (val > result)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
519 result = val;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
520 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
521
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
522 if (all_inf_or_nan)
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
523 result = 0.0;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
524
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
525 return result;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
526 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
527
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
528 static double
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
529 pr_min_internal (const Matrix& m)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
530 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
531 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
532 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
533
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
534 double result = std::numeric_limits<double>::max ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
535
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
536 bool all_inf_or_nan = true;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
537
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
538 for (octave_idx_type j = 0; j < nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
539 for (octave_idx_type i = 0; i < nr; i++)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
540 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
541 double val = m(i,j);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
542 if (! octave::math::finite (val))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
543 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
544
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
545 all_inf_or_nan = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
546
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
547 if (val < result)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
548 result = val;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
549 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
550
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
551 if (all_inf_or_nan)
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
552 result = 0.0;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
553
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
554 return result;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
555 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
556
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
557 // 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
558
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
559 static void
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
560 set_real_format (int digits, bool inf_or_nan, bool int_only, int &fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
561 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
562 static float_format fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
563
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
564 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
565
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
566 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
567
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
568 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
569 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
570 fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
571 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
572 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
573 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
574 {
17847
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
575 fw = digits < 0 ? 5 : digits + 4;
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
576 if (inf_or_nan && fw < 5)
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
577 fw = 5;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
578 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
579 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
580 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
581 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
582 fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
583 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
584 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
585 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
586 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
587 fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
588 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
589 }
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
590 else if (inf_or_nan || int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
591 {
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
592 fw = 1 + digits;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
593 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
594 fw = 4;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
595 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
596 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
597 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
598 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
599 if (digits > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
600 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
601 ld = digits;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
602 rd = prec > digits ? prec - digits : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
603 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
604 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
605 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
606 ld = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
607 rd = prec > digits ? prec - digits : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
608 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
609
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
610 fw = 1 + ld + 1 + rd;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
611 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
612 fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
613 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
614
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
615 if (! (rat_format || bank_format || hex_format || bit_format)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
616 && (fw > Voutput_max_field_width || print_e || print_g || print_eng))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
617 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
618 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
619 fmt = float_format ();
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
620 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
621 {
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
622 // e+ddd
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
623 int ex = 5;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
624
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
625 if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
626 {
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
627 // -ddd.
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
628 fw = 5 + prec + ex;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
629 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
630 fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
631 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
632 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
633 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
634 {
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
635 // -d.
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
636 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
637 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
638 fw = 4;
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
639 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
640 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
641 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
642
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
643 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
644 fmt.uppercase ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
645 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
646 else if (! bank_format && (inf_or_nan || int_only))
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
647 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
648 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
649 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
650
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
651 curr_real_fmt = &fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
652 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
653
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
654 static void
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
655 set_format (double d, int& fw)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
656 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
657 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
658 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
659
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
660 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
661 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
662
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
663 bool inf_or_nan = (octave::math::isinf (d) || octave::math::isnan (d));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
664
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
665 bool int_only = (! inf_or_nan && octave::math::x_nint (d) == d);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
666
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
667 double d_abs = d < 0.0 ? -d : d;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
668
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
669 int digits = (inf_or_nan || d_abs == 0.0) ? 0 : num_digits (d_abs);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
670
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
671 set_real_format (digits, inf_or_nan, int_only, fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
672 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
673
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
674 static inline void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
675 set_format (double d)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
676 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
677 int fw;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
678 set_format (d, fw);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
679 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
680
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
681 static void
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
682 set_real_matrix_format (int x_max, int x_min, bool inf_or_nan,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
683 int int_or_inf_or_nan, int& fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
684 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
685 static float_format fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
686
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
687 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
688
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
689 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
690
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
691 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
692 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
693 fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
694 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
695 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
696 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
697 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
698 int digits = x_max > x_min ? x_max : x_min;
17847
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
699 fw = digits <= 0 ? 5 : digits + 4;
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
700 if (inf_or_nan && fw < 5)
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
701 fw = 5;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
702 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
703 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
704 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
705 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
706 fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
707 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
708 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
709 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
710 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
711 fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
712 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
713 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
714 else if (Vfixed_point_format && ! print_g)
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
715 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
716 rd = prec;
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
717 fw = rd + 2;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
718 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
719 fw = 4;
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
720 }
1715
6f4631c7118c [project @ 1996-01-08 07:57:04 by jwe]
jwe
parents: 1658
diff changeset
721 else if (int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
722 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
723 int digits = x_max > x_min ? x_max : x_min;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
724 fw = digits <= 0 ? 2 : digits + 1;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
725 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
726 fw = 4;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
727 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
728 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
729 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
730 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
731 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
732 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
733 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
734 ld_max = x_max;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
735 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
736 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
737 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
738 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
739 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
740 ld_max = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
741 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
742 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
743 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
744
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
745 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
746 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
747 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
748 ld_min = x_min;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
749 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
750 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
751 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
752 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
753 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
754 ld_min = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
755 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
756 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
757 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
758
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
759 ld = ld_max > ld_min ? ld_max : ld_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
760 rd = rd_max > rd_min ? rd_max : rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
761
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
762 fw = 1 + ld + 1 + rd;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
763 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
764 fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
765 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
766
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
767 if (! (rat_format || bank_format || hex_format || bit_format)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
768 && (print_e
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
769 || print_eng || print_g
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
770 || (! Vfixed_point_format && fw > Voutput_max_field_width)))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
771 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
772 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
773 fmt = float_format ();
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
774 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
775 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
776 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
777 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
778 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
779
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
780 if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
781 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
782 fw = 4 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
783 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
784 fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
785 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
786 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
787 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
788 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
789 fw = 2 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
790 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
791 fw = 4;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
792 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
793 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
794 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
795
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
796 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
797 fmt.uppercase ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
798 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
799 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
800 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
801 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
802 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
803
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
804 curr_real_fmt = &fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
805 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
806
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
807 static void
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
808 set_format (const Matrix& m, int& fw, double& scale)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
809 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
810 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
811 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
812
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
813 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
814 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
815
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
816 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
817
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
818 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
819
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
820 Matrix m_abs = m.abs ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
821 double max_abs = pr_max_internal (m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
822 double min_abs = pr_min_internal (m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
823
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
824 int x_max = max_abs == 0.0 ? 0 : num_digits (max_abs);
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
825
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
826 int x_min = min_abs == 0.0 ? 0 : num_digits (min_abs);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
827
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
828 scale = (x_max == 0 || int_or_inf_or_nan)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
829 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1));
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
830
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
831 set_real_matrix_format (x_max, x_min, inf_or_nan, int_or_inf_or_nan, fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
832 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
833
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
834 static inline void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
835 set_format (const Matrix& m)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
836 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
837 int fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
838 double scale;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
839 set_format (m, fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
840 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
841
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
842 static void
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
843 set_complex_format (int x_max, int x_min, int r_x, bool inf_or_nan,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
844 int int_only, int& r_fw, int& i_fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
845 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
846 static float_format r_fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
847 static float_format i_fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
848
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
849 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
850
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
851 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
852
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
853 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
854 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
855 i_fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
856 r_fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
857 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
858 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
859 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
860 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
861 int digits = r_x;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
862 i_fw = 0;
17847
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
863 r_fw = digits <= 0 ? 5 : digits + 4;
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
864 if (inf_or_nan && r_fw < 5)
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
865 r_fw = 5;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
866 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
867 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
868 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
869 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
870 r_fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
871 i_fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
872 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
873 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
874 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
875 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
876 r_fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
877 i_fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
878 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
879 }
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
880 else if (inf_or_nan || int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
881 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
882 int digits = x_max > x_min ? x_max : x_min;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
883 i_fw = digits <= 0 ? 1 : digits;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
884 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
885 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
886 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
887 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
888 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
889 }
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
890 rd = r_fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
891 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
892 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
893 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
894 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
895 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
896 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
897 ld_max = x_max;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
898 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
899 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
900 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
901 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
902 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
903 ld_max = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
904 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
905 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
906 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
907
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
908 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
909 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
910 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
911 ld_min = x_min;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
912 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
913 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
914 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
915 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
916 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
917 ld_min = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
918 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
919 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
920 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
921
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
922 ld = ld_max > ld_min ? ld_max : ld_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
923 rd = rd_max > rd_min ? rd_max : rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
924
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
925 i_fw = ld + 1 + rd;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
926 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
927 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
928 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
929 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
930 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
931 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
932 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
933
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
934 if (! (rat_format || bank_format || hex_format || bit_format)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
935 && (r_fw > Voutput_max_field_width || print_e || print_eng || print_g))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
936 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
937 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
938 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
939 r_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
940 i_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
941 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
942 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
943 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
944 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
945 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
946 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
947
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
948 if (print_eng)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
949 {
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21547
diff changeset
950 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
951 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
952 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
953 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
954 i_fw = 5;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
955 r_fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
956 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
957 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
958 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
959 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
960 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
961 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
962 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
963 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
964 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
965 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
966 i_fw = 3;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
967 r_fw = 4;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
968 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
969 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
970 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
971 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
972 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
973
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
974 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
975 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
976 r_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
977 i_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
978 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
979 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
980 else if (! bank_format && (inf_or_nan || int_only))
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
981 {
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
982 r_fmt = float_format (r_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
983 i_fmt = float_format (i_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
984 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
985 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
986 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
987 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
988 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
989 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
990
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
991 curr_real_fmt = &r_fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
992 curr_imag_fmt = &i_fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
993 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
994
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
995 static void
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
996 set_format (const Complex& c, int& r_fw, int& i_fw)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
997 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
998 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
999 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1000
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1001 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1002 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1003
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1004 double rp = c.real ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1005 double ip = c.imag ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1006
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1007 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
1008
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1009 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
1010 && octave::math::x_nint (ip) == ip);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1011
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1012 double r_abs = rp < 0.0 ? -rp : rp;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1013 double i_abs = ip < 0.0 ? -ip : ip;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1014
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1015 int r_x = (! octave::math::finite (rp)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1016 || r_abs == 0.0) ? 0 : num_digits (r_abs);
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1017
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1018 int i_x = (! octave::math::finite (ip)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
1019 || i_abs == 0.0) ? 0 : num_digits (i_abs);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1020
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1021 int x_max, x_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1022
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1023 if (r_x > i_x)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1024 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1025 x_max = r_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1026 x_min = i_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1027 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1028 else
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1029 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1030 x_max = i_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1031 x_min = r_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1032 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1033
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
1034 set_complex_format (x_max, x_min, r_x, inf_or_nan, int_only, r_fw, i_fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1035 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1036
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1037 static inline void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
1038 set_format (const Complex& c)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1039 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1040 int r_fw, i_fw;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1041 set_format (c, r_fw, i_fw);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1042 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1043
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1044 static void
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
1045 set_complex_matrix_format (int x_max, int x_min, int r_x_max,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1046 int r_x_min, bool inf_or_nan,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1047 int int_or_inf_or_nan, int& r_fw, int& i_fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1048 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1049 static float_format r_fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1050 static float_format i_fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1051
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1052 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1053
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1054 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1055
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1056 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1057 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1058 i_fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1059 r_fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1060 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1061 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1062 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1063 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1064 int digits = r_x_max > r_x_min ? r_x_max : r_x_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1065 i_fw = 0;
17847
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
1066 r_fw = digits <= 0 ? 5 : digits + 4;
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
1067 if (inf_or_nan && r_fw < 5)
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
1068 r_fw = 5;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1069 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1070 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1071 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1072 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1073 r_fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1074 i_fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1075 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1076 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1077 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1078 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1079 r_fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1080 i_fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1081 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1082 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1083 else if (Vfixed_point_format && ! print_g)
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
1084 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
1085 rd = prec;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1086 i_fw = rd + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1087 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1088 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1089 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1090 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1091 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1092 }
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
1093 }
1715
6f4631c7118c [project @ 1996-01-08 07:57:04 by jwe]
jwe
parents: 1658
diff changeset
1094 else if (int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1095 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1096 int digits = x_max > x_min ? x_max : x_min;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1097 i_fw = digits <= 0 ? 1 : digits;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1098 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1099 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1100 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1101 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1102 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1103 }
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
1104 rd = r_fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1105 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1106 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1107 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1108 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1109 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1110 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1111 ld_max = x_max;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1112 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1113 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1114 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1115 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1116 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1117 ld_max = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1118 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1119 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1120 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1121
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1122 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1123 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1124 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1125 ld_min = x_min;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1126 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1127 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1128 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1129 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1130 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1131 ld_min = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1132 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1133 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1134 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1135
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1136 ld = ld_max > ld_min ? ld_max : ld_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1137 rd = rd_max > rd_min ? rd_max : rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1138
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1139 i_fw = ld + 1 + rd;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1140 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
1141 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1142 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1143 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1144 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1145 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1146 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1147
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1148 if (! (rat_format || bank_format || hex_format || bit_format)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1149 && (print_e
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1150 || print_eng || print_g
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1151 || (! Vfixed_point_format && r_fw > Voutput_max_field_width)))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1152 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1153 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1154 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1155 r_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1156 i_fmt = float_format ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1157 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1158 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1159 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1160 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1161 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
1162 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1163
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1164 if (print_eng)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1165 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1166 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
1167 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
1168 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
1169 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1170 i_fw = 5;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1171 r_fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1172 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1173 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
1174 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
1175 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1176 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1177 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1178 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
1179 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
1180 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
1181 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1182 i_fw = 3;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1183 r_fw = 4;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1184 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1185 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
1186 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
1187 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1188 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1189
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1190 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1191 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1192 r_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1193 i_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1194 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1195 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
1196 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
1197 {
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1198 r_fmt = float_format (r_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1199 i_fmt = float_format (i_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1200 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1201 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1202 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1203 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
1204 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
1205 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1206
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1207 curr_real_fmt = &r_fmt;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1208 curr_imag_fmt = &i_fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1209 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1210
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1211 static void
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1212 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1213 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1214 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1215 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1216
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1217 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1218 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1219
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1220 Matrix rp = real (cm);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1221 Matrix ip = imag (cm);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1222
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1223 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
1224
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1225 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
1226 && 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
1227
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1228 Matrix r_m_abs = rp.abs ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1229 double r_max_abs = pr_max_internal (r_m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1230 double r_min_abs = pr_min_internal (r_m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1231
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1232 Matrix i_m_abs = ip.abs ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1233 double i_max_abs = pr_max_internal (i_m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1234 double i_min_abs = pr_min_internal (i_m_abs);
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1235
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1236 int r_x_max = r_max_abs == 0.0 ? 0 : num_digits (r_max_abs);
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1237
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1238 int r_x_min = r_min_abs == 0.0 ? 0 : num_digits (r_min_abs);
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1239
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1240 int i_x_max = i_max_abs == 0.0 ? 0 : num_digits (i_max_abs);
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1241
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1242 int i_x_min = i_min_abs == 0.0 ? 0 : num_digits (i_min_abs);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1243
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1244 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1245 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1246
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1247 scale = (x_max == 0 || int_or_inf_or_nan)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1248 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1));
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1249
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6803
diff changeset
1250 set_complex_matrix_format (x_max, x_min, r_x_max, r_x_min, inf_or_nan,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1251 int_or_inf_or_nan, r_fw, i_fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1252 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1253
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1254 static inline void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
1255 set_format (const ComplexMatrix& cm)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1256 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1257 int r_fw, i_fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1258 double scale;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1259 set_format (cm, r_fw, i_fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1260 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1261
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1262 static void
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1263 set_range_format (int x_max, int x_min, int all_ints, int& fw)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1264 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1265 static float_format fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1266
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1267 int prec = Voutput_precision;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1268
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1269 int ld, rd;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1270
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1271 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1272 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1273 fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1274 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1275 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1276 else if (bank_format)
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 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
1279 fw = digits < 0 ? 5 : digits + 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1280 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1281 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1282 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1283 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1284 fw = 2 * sizeof (double);
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1285 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1286 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1287 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1288 {
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1289 fw = 8 * sizeof (double);
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1290 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1291 }
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1292 else if (all_ints)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1293 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1294 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
1295 fw = digits + 1;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
1296 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1297 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1298 else if (Vfixed_point_format && ! print_g)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1299 {
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1300 rd = prec;
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1301 fw = rd + 3;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1302 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1303 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1304 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1305 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1306 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1307 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1308 ld_max = x_max;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1309 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1310 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1311 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1312 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1313 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1314 ld_max = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1315 rd_max = prec > x_max ? prec - x_max : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1316 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1317 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1318
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1319 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1320 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1321 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1322 ld_min = x_min;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1323 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1324 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1325 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1326 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1327 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1328 ld_min = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1329 rd_min = prec > x_min ? prec - x_min : prec;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1330 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1331 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1332
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1333 ld = ld_max > ld_min ? ld_max : ld_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1334 rd = rd_max > rd_min ? rd_max : rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1335
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1336 fw = ld + rd + 3;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1337 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1338
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1339 if (! (rat_format || bank_format || hex_format || bit_format)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1340 && (print_e
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1341 || print_eng || print_g
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1342 || (! Vfixed_point_format && fw > Voutput_max_field_width)))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1343 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1344 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1345 fmt = float_format ();
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1346 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1347 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1348 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1349 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
1350 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1351
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1352 if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1353 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1354 fw = 5 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1355 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
1356 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1357 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1358 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1359 fw = 3 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1360 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
1361 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1362 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1363
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1364 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1365 fmt.uppercase ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1366 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
1367 else if (! bank_format && all_ints)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1368 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1369 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1370 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1371
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1372 curr_real_fmt = &fmt;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1373 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1374
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1375 static void
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1376 set_format (const Range& r, int& fw, double& scale)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1377 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1378 curr_real_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1379 curr_imag_fmt = 0;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1380
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1381 if (free_format)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1382 return;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1383
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1384 double r_min = r.base ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1385 double r_max = r.limit ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1386
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1387 if (r_max < r_min)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1388 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1389 double tmp = r_max;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1390 r_max = r_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1391 r_min = tmp;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1392 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1393
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1394 bool all_ints = r.all_elements_are_ints ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1395
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1396 double max_abs = r_max < 0.0 ? -r_max : r_max;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1397 double min_abs = r_min < 0.0 ? -r_min : r_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1398
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1399 int x_max = max_abs == 0.0 ? 0 : num_digits (max_abs);
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1400
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
1401 int x_min = min_abs == 0.0 ? 0 : num_digits (min_abs);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1402
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1403 scale = (x_max == 0 || all_ints)
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
1404 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1));
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1405
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1406 set_range_format (x_max, x_min, all_ints, fw);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1407 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1408
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1409 static inline void
164
e2c950dd96d2 [project @ 1993-10-18 19:32:00 by jwe]
jwe
parents: 127
diff changeset
1410 set_format (const Range& r)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1411 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1412 int fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1413 double scale;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1414 set_format (r, fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1415 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1416
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1417 union equiv
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1418 {
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1419 double d;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1420 unsigned char i[sizeof (double)];
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1421 };
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1422
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1423 #define PRINT_CHAR_BITS(os, c) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1424 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1425 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1426 unsigned char ctmp = c; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1427 char stmp[9]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1428 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1429 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1430 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1431 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1432 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1433 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1434 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1435 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1436 stmp[8] = '\0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1437 os << stmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1438 } \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1439 while (0)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1440
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1441 #define PRINT_CHAR_BITS_SWAPPED(os, c) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1442 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1443 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1444 unsigned char ctmp = c; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1445 char stmp[9]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1446 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1447 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1448 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1449 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1450 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1451 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1452 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1453 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1454 stmp[8] = '\0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1455 os << stmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1456 } \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1457 while (0)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1458
2522
4f095783ee43 [project @ 1996-11-15 20:00:59 by jwe]
jwe
parents: 2447
diff changeset
1459 static void
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1460 pr_any_float (const float_format *fmt, std::ostream& os, double d, int fw = 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1461 {
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
1462 if (fmt)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1463 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1464 // Unless explicitly asked for, always print in big-endian format
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1465 // for hex and bit formats.
5544
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1466 //
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1467 // {bit,hex}_format == 1: print big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1468 // {bit,hex}_format == 2: print native
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
1469
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1470 if (hex_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1471 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1472 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1473
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1474 equiv tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1475 tmp.d = d;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1476
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1477 // Unless explicitly asked for, always print in big-endian format.
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1478
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1479 // FIXME: will bad things happen if we are
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1480 // interrupted before resetting the format flags and fill
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1481 // character?
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1482
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1483 octave::mach_info::float_format flt_fmt =
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1484 octave::mach_info::native_float_format ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1485
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1486 os.fill ('0');
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1487 os.flags (std::ios::right | std::ios::hex);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1488
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1489 if (hex_format > 1
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1490 || 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
1491 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1492 for (size_t i = 0; i < sizeof (double); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1493 os << std::setw (2) << static_cast<int> (tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1494 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1495 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1496 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1497 for (int i = sizeof (double) - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1498 os << std::setw (2) << static_cast<int> (tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1499 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1500 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1501 else if (bit_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1502 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1503 equiv tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1504 tmp.d = d;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1505
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1506 octave::mach_info::float_format flt_fmt =
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1507 octave::mach_info::native_float_format ();
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1508
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1509 if (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
1510 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1511 for (size_t i = 0; i < sizeof (double); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1512 PRINT_CHAR_BITS (os, tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1513 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1514 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1515 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1516 if (bit_format > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1517 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1518 for (size_t i = 0; i < sizeof (double); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1519 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1520 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1521 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1522 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1523 for (int i = sizeof (double) - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1524 PRINT_CHAR_BITS (os, tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1525 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1526 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1527 }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1528 else if (octave::math::is_NA (d))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1529 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1530 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1531
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1532 if (fw > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1533 os << std::setw (fw) << "NA";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1534 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1535 os << "NA";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1536 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1537 else if (rat_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1538 os << pr_rational_float (*fmt, d);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1539 else if (octave::math::isinf (d))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1540 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1541 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1542
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1543 const char *s;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1544 if (d < 0.0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1545 s = "-Inf";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1546 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1547 s = "Inf";
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 if (fw > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1550 os << std::setw (fw) << s;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1551 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1552 os << s;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1553 }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1554 else if (octave::math::isnan (d))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1555 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1556 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1557
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1558 if (fw > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1559 os << std::setw (fw) << "NaN";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1560 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1561 os << "NaN";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1562 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1563 else if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1564 os << pr_engineering_float (*fmt, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1565 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1566 os << pr_formatted_float (*fmt, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1567 }
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
1568 else
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
1569 os << d;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1570 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1571
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1572 static inline void
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1573 pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1574 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1575 if (Vfixed_point_format && ! print_g && scale != 1.0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1576 d /= scale;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1577
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1578 pr_any_float (curr_real_fmt, os, d, fw);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1579 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1580
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1581 static inline void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1582 pr_imag_float (std::ostream& os, double d, int fw = 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1583 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1584 pr_any_float (curr_imag_fmt, os, d, fw);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1585 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1586
2522
4f095783ee43 [project @ 1996-11-15 20:00:59 by jwe]
jwe
parents: 2447
diff changeset
1587 static void
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1588 pr_complex (std::ostream& os, const Complex& c, int r_fw = 0,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1589 int i_fw = 0, double scale = 1.0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1590 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1591 Complex tmp
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1592 = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1593
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1594 double r = tmp.real ();
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1595
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1596 pr_float (os, r, r_fw);
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1597
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1598 if (! bank_format)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1599 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1600 double i = tmp.imag ();
4349
a6c22c2c9b09 [project @ 2003-02-21 18:59:07 by jwe]
jwe
parents: 4270
diff changeset
1601 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
1602 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1603 os << " - ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1604 i = -i;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1605 pr_imag_float (os, i, i_fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1606 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1607 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1608 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1609 if (hex_format || bit_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1610 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1611 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1612 os << " + ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1613
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1614 pr_imag_float (os, i, i_fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1615 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1616 os << "i";
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1617 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1618 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1619
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1620 static void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1621 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
1622 bool pr_as_read_syntax)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1623 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1624 assert (nr == 0 || nc == 0);
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1625
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1626 if (pr_as_read_syntax)
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1627 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1628 if (nr == 0 && nc == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1629 os << "[]";
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1630 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1631 os << "zeros (" << nr << ", " << nc << ")";
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1632 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1633 else
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1634 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1635 os << "[]";
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1636
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1637 if (Vprint_empty_dimensions)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1638 os << "(" << nr << "x" << nc << ")";
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1639 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1640 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1641
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1642 static void
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1643 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
1644 bool pr_as_read_syntax)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1645 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1646 assert (dims.any_zero ());
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1647
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1648 if (pr_as_read_syntax)
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1649 os << "zeros (" << dims.str (',') << ")";
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1650 else
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1651 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1652 os << "[]";
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1653
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1654 if (Vprint_empty_dimensions)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1655 os << "(" << dims.str () << ")";
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1656 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1657 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1658
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1659 static void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1660 pr_scale_header (std::ostream& os, double scale)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1661 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1662 if (Vfixed_point_format && ! print_g && scale != 1.0)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1663 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1664 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1665
3568
58549b931ad5 [project @ 2000-02-03 10:21:54 by jwe]
jwe
parents: 3548
diff changeset
1666 os << " "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1667 << std::setw (8) << std::setprecision (1)
21662
5b9868c2e212 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21583
diff changeset
1668 << 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
1669 << scale
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1670 << " *\n";
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1671
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1672 if (! Vcompact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1673 os << "\n";
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1674 }
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1675 }
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1676
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1677 static void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1678 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
1679 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
1680 {
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1681 if (total_width > max_width && Vsplit_long_rows)
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1682 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1683 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1684
4833
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
1685 if (col != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1686 {
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1687 if (Vcompact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1688 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1689 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1690 os << "\n\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1691 }
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1692
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1693 octave_idx_type num_cols = lim - col;
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1694
3548
ab7fa5a8f23f [project @ 2000-02-03 01:17:15 by jwe]
jwe
parents: 3538
diff changeset
1695 os << std::setw (extra_indent) << "";
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1696
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1697 if (num_cols == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1698 os << " Column " << col + 1 << ":\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1699 else if (num_cols == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1700 os << " Columns " << col + 1 << " and " << lim << ":\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1701 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1702 os << " Columns " << col + 1 << " through " << lim << ":\n";
2915
649549662cf6 [project @ 1997-04-30 20:51:40 by jwe]
jwe
parents: 2907
diff changeset
1703
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1704 if (! Vcompact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1705 os << "\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1706 }
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1707 }
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1708
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
1709 template <typename T>
6018
bda649f500bd [project @ 2006-10-02 17:23:18 by jwe]
jwe
parents: 6015
diff changeset
1710 /* static */ inline void
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1711 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
1712 {
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1713 if (val > T (0))
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1714 os << plus_format_chars[0];
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1715 else if (val < T (0))
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1716 os << plus_format_chars[1];
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1717 else
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1718 os << plus_format_chars[2];
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1719 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1720
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1721 void
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1722 octave_print_internal (std::ostream&, char, bool)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1723 {
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1724 panic_impossible ();
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1725 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1726
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1727 void
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1728 octave_print_internal (std::ostream& os, double d,
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1729 bool pr_as_read_syntax)
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1730 {
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1731 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
1732 os << d;
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1733 else if (plus_format)
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1734 pr_plus_format (os, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1735 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1736 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1737 set_format (d);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1738 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1739 os << d;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1740 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1741 pr_float (os, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1742 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1743 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1744
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1745 void
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1746 octave_print_internal (std::ostream& os, const Matrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1747 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1748 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1749 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1750 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1751
2408
e22aae3ccfad [project @ 1996-10-15 16:37:52 by jwe]
jwe
parents: 2387
diff changeset
1752 if (nr == 0 || nc == 0)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1753 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
1754 else if (plus_format && ! pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1755 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1756 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1757 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1758 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1759 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1760 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1761
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1762 pr_plus_format (os, m(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1763 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1764
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1765 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1766 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1767 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1768 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1769 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1770 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1771 int fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1772 double scale = 1.0;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1773 set_format (m, fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1774 int column_width = fw + 2;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1775 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
1776 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
1777
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1778 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1779 max_width -= 4;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1780 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1781 max_width -= extra_indent;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1782
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1783 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1784 max_width = 0;
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1785
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1786 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1787 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1788 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1789 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1790
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1791 os << m;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1792
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1793 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1794 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1795
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1796 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1797 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1798
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1799 octave_idx_type inc = nc;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1800 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
1801 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1802 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1803 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1804 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1805 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1806
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1807 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1808 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1809 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
1810 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1811 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1812 while (col < nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1813 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1814 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1815
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1816 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
1817 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1818 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1819
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1820 if (i == 0 && j == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1821 os << "[ ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1822 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1823 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1824 if (j > col && j < lim)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1825 os << ", ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1826 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1827 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1828 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1829
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1830 pr_float (os, m(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1831 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1832
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1833 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1834
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1835 if (col >= nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1836 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1837 if (i == nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1838 os << " ]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1839 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1840 os << ";\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1841 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1842 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1843 os << " ...\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1844 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1845 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1846 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1847 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1848 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1849 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1850
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1851 pr_scale_header (os, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1852
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1853 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
1854 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1855 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1856
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1857 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
1858 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1859
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1860 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
1861 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1862 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1863
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1864 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
1865 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1866 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1867
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1868 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1869
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1870 pr_float (os, m(i,j), fw, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1871 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1872
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1873 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1874 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1875 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1876 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1877 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1878 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1879 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1880
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1881 void
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1882 octave_print_internal (std::ostream& os, const DiagMatrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1883 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1884 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1885 octave_idx_type nr = m.rows ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1886 octave_idx_type nc = m.columns ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1887
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1888 if (nr == 0 || nc == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1889 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
1890 else if (plus_format && ! pr_as_read_syntax)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1891 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1892 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1893 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1894 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1895 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1896 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1897
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1898 pr_plus_format (os, m(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1899 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1900
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1901 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1902 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1903 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1904 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1905 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1906 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1907 int fw;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1908 double scale = 1.0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1909 set_format (Matrix (m.diag ()), fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1910 int column_width = fw + 2;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1911 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
1912 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
1913
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1914 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1915 max_width -= 4;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1916 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1917 max_width -= extra_indent;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1918
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1919 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1920 max_width = 0;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1921
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1922 if (free_format)
10315
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 (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1925 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1926
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1927 os << Matrix (m);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1928
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1929 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1930 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1931
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1932 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1933 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1934
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1935 octave_idx_type inc = nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1936 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
1937 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1938 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1939 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1940 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1941 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1942
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1943 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1944 {
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1945 os << "diag (";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1946
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1947 octave_idx_type col = 0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1948 while (col < nc)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1949 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1950 octave_idx_type lim = col + inc < nc ? col + inc : nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1951
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1952 for (octave_idx_type j = col; j < lim; j++)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1953 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
1954 octave_quit ();
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1955
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1956 if (j == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1957 os << "[ ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1958 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1959 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1960 if (j > col && j < lim)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1961 os << ", ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1962 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1963 os << " ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1964 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1965
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1966 pr_float (os, m(j,j));
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1967 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1968
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1969 col += inc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1970
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1971 if (col >= nc)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1972 os << " ]";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1973 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1974 os << " ...\n";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1975 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1976 os << ")";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1977 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1978 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1979 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1980 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1981
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1982 os << "Diagonal Matrix\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1983 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1984 os << "\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1985
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1986 pr_scale_header (os, scale);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1987
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21748
diff changeset
1988 // kluge. Get the true width of a number.
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1989 int zero_fw;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1990
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1991 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1992 std::ostringstream tmp_oss;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1993 pr_float (tmp_oss, 0.0, fw, scale);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1994 zero_fw = tmp_oss.str ().length ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1995 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1996
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1997 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
1998 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1999 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2000
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2001 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
2002 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2003
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2004 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
2005 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2006 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2007
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2008 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
2009 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2010 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2011
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2012 os << " ";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2013
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2014 if (i == j)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2015 pr_float (os, m(i,j), fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2016 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2017 os << std::setw (zero_fw) << '0';
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2018
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2019 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2020
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2021 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2022 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2023 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2024 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2025 }
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 }
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2028
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2029 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
2030 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
2031 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
2032 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2033
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2034 if (nda.is_empty ())
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2035 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
2036 else
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2037 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2038
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2039 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
2040
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2041 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
2042
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2043 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
2044
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2045 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
2046
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2047 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
2048 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
2049
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2050 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
2051 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
2052
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2053 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
2054 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2055 octave_quit ();
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2056
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2057 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
2058
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2059 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
2060 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2061 nm += "(:,:,";
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2062
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2063 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
2064
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2065 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
2066 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2067 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
2068
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2069 if (k < ndims - 1)
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2070 buf << ",";
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2071 else
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2072 buf << ")";
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2073 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2074
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2075 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
2076 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2077
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2078 Array<idx_vector> idx (dim_vector (ndims, 1));
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2079
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2080 idx(0) = idx_vector (':');
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2081 idx(1) = idx_vector (':');
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2082
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2083 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
2084 idx(k) = idx_vector (ra_idx(k));
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2085
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2086 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
2087 = 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
2088
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2089 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
2090 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2091 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
2092 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2093 else
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2094 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2095 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
2096 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
2097 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2098
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2099 if (i < m)
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2100 NDA_T::increment_index (ra_idx, dims, 2);
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2101 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2102 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2103 }
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
2104
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2105 void
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2106 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
2107 bool pr_as_read_syntax, int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2108 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2109 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2110 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2111 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2112 case 2:
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19318
diff changeset
2113 octave_print_internal (os, Matrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2114 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2115 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2116
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2117 default:
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_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
2119 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2120 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2121 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2122
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
2123 template <>
6018
bda649f500bd [project @ 2006-10-02 17:23:18 by jwe]
jwe
parents: 6015
diff changeset
2124 /* static */ inline void
6015
a104f362b5d4 [project @ 2006-10-02 02:13:53 by jwe]
jwe
parents: 6008
diff changeset
2125 pr_plus_format<> (std::ostream& os, const Complex& c)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2126 {
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2127 double rp = c.real ();
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2128 double ip = c.imag ();
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2129
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2130 if (rp == 0.0)
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2131 {
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2132 if (ip == 0.0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2133 os << " ";
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2134 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2135 os << "i";
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2136 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2137 else if (ip == 0.0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
2138 pr_plus_format (os, rp);
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2139 else
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2140 os << "c";
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2141 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2142
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2143 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2144 octave_print_internal (std::ostream& os, const Complex& c,
17867
49d573a1deda avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
2145 bool pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2146 {
17867
49d573a1deda avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
2147 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
2148 os << c;
49d573a1deda avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
2149 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
2150 pr_plus_format (os, c);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2151 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2152 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2153 set_format (c);
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2154 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2155 os << c;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2156 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2157 pr_complex (os, c);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2158 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2159 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2160
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2161 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2162 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
2163 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2164 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2165 octave_idx_type nr = cm.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2166 octave_idx_type nc = cm.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2167
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2168 if (nr == 0 || nc == 0)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2169 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
2170 else if (plus_format && ! pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2171 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2172 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2173 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2174 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2175 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2176 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2177
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2178 pr_plus_format (os, cm(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2179 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2180
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2181 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2182 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2183 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2184 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2185 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2186 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2187 int r_fw, i_fw;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
2188 double scale = 1.0;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
2189 set_format (cm, r_fw, i_fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2190 int column_width = i_fw + r_fw;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2191 column_width += (rat_format || bank_format || hex_format
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2192 || bit_format) ? 2 : 7;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2193 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
2194 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
2195
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2196 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2197 max_width -= 4;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
2198 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2199 max_width -= extra_indent;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
2200
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
2201 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2202 max_width = 0;
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2203
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2204 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2205 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2206 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2207 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2208
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2209 os << cm;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2210
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2211 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2212 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2213
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2214 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2215 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2216
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2217 octave_idx_type inc = nc;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
2218 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
2219 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2220 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2221 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2222 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2223 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2224
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2225 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2226 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2227 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
2228 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2229 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2230 while (col < nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2231 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2232 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2233
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2234 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
2235 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2236 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2237
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2238 if (i == 0 && j == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2239 os << "[ ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2240 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2241 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2242 if (j > col && j < lim)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2243 os << ", ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2244 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2245 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2246 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2247
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2248 pr_complex (os, cm(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2249 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2250
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2251 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2252
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2253 if (col >= nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2254 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2255 if (i == nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2256 os << " ]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2257 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2258 os << ";\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2259 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2260 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2261 os << " ...\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2262 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2263 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2264 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2265 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2266 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2267 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2268
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2269 pr_scale_header (os, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2270
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2271 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
2272 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2273 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2274
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2275 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
2276 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2277
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2278 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
2279 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2280 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2281
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2282 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
2283 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2284 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2285
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2286 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2287
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2288 pr_complex (os, cm(i,j), r_fw, i_fw, scale);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2289 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2290
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2291 if (i < nr - 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2292 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2293 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2294 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2295 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2296 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2297 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2298
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2299 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2300 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2301 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2302 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2303 octave_idx_type nr = cm.rows ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2304 octave_idx_type nc = cm.columns ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2305
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2306 if (nr == 0 || nc == 0)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2307 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
2308 else if (plus_format && ! pr_as_read_syntax)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2309 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2310 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2311 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2312 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2313 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2314 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2316 pr_plus_format (os, cm(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2317 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2318
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2319 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2320 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2321 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2322 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2323 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2324 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2325 int r_fw, i_fw;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2326 double scale = 1.0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2327 set_format (ComplexMatrix (cm.diag ()), r_fw, i_fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2328 int column_width = i_fw + r_fw;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2329 column_width += (rat_format || bank_format || hex_format
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2330 || bit_format) ? 2 : 7;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2331 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
2332 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
2333
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2334 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2335 max_width -= 4;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2336 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2337 max_width -= extra_indent;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2338
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2339 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2340 max_width = 0;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2341
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2342 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2343 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2344 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2345 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2346
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2347 os << ComplexMatrix (cm);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2348
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2349 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2350 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2351
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2352 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2353 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2354
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2355 octave_idx_type inc = nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2356 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
2357 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2358 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2359 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2360 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2361 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2362
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2363 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2364 {
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2365 os << "diag (";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2366
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2367 octave_idx_type col = 0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2368 while (col < nc)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2369 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2370 octave_idx_type lim = col + inc < nc ? col + inc : nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2371
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2372 for (octave_idx_type j = col; j < lim; j++)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2373 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
2374 octave_quit ();
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2375
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2376 if (j == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2377 os << "[ ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2378 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2379 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2380 if (j > col && j < lim)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2381 os << ", ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2382 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2383 os << " ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2384 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2385
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2386 pr_complex (os, cm(j,j));
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2387 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2388
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2389 col += inc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2390
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2391 if (col >= nc)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2392 os << " ]";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2393 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2394 os << " ...\n";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2395 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2396 os << ")";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2397 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2398 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2399 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2400 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2401
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2402 os << "Diagonal Matrix\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2403 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2404 os << "\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2405
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2406 pr_scale_header (os, scale);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2407
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21748
diff changeset
2408 // kluge. Get the true width of a number.
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2409 int zero_fw;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2410
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2411 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2412 std::ostringstream tmp_oss;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2413 pr_complex (tmp_oss, Complex (0.0), r_fw, i_fw, scale);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2414 zero_fw = tmp_oss.str ().length ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2415 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2416
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2417 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
2418 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2419 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2420
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2421 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
2422 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2423
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2424 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
2425 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2426 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2427
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2428 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
2429 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2430 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2431
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2432 os << " ";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2433
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2434 if (i == j)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2435 pr_complex (os, cm(i,j), r_fw, i_fw, scale);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2436 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2437 os << std::setw (zero_fw) << '0';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2438 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2439
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2440 if (i < nr - 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2441 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2442 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2443 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2444 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2445 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2446 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2447
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2448 void
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2449 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
2450 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
2451 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2452 octave_idx_type nr = m.rows ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2453 octave_idx_type nc = m.columns ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2454
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2455 if (nr == 0 || nc == 0)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2456 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
2457 else if (plus_format && ! pr_as_read_syntax)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2458 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2459 for (octave_idx_type i = 0; i < nr; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2460 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2461 for (octave_idx_type j = 0; j < nc; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2462 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2463 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2464
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2465 pr_plus_format (os, m(i,j));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2466 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2467
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2468 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2469 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2470 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2471 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2472 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2473 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2474 int fw = 2;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2475 int column_width = fw + 2;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2476 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
2477 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
2478
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2479 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2480 max_width -= 4;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2481 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2482 max_width -= extra_indent;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2483
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2484 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2485 max_width = 0;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2486
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2487 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2488 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2489 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2490 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2491
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2492 os << Matrix (m);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2493
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2494 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2495 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2496
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2497 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2498 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2499
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2500 octave_idx_type inc = nc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2501 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
2502 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2503 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2504 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2505 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2506 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2507
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2508 if (pr_as_read_syntax)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2509 {
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18816
diff changeset
2510 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
2511
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2512 os << "eye (";
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18816
diff changeset
2513 os << ":, ";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2514
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2515 octave_idx_type col = 0;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2516 while (col < nc)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2517 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2518 octave_idx_type lim = col + inc < nc ? col + inc : nc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2519
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2520 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
2521 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
2522 octave_quit ();
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2523
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2524 if (j == 0)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2525 os << "[ ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2526 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2527 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2528 if (j > col && j < lim)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2529 os << ", ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2530 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2531 os << " ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2532 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2533
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2534 os << pvec (j);
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2535 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2536
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2537 col += inc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2538
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2539 if (col >= nc)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2540 os << " ]";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2541 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2542 os << " ...\n";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2543 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2544 os << ")";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2545 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2546 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2547 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2548 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2549
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2550 os << "Permutation Matrix\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2551 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2552 os << "\n";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2553
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2554 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
2555 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2556 octave_idx_type lim = col + inc < nc ? col + inc : nc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2557
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2558 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
2559 extra_indent);
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 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
2562 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2563 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2564
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2565 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
2566 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2567 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2568
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2569 os << " ";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2570
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2571 os << std::setw (fw) << m(i,j);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2572 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2573
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2574 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2575 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2576 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2577 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2578 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2579 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2580 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2581
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2582 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2583 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
2584 bool pr_as_read_syntax, int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2585 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2586 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2587 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2588 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2589 case 2:
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19318
diff changeset
2590 octave_print_internal (os, ComplexMatrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2591 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2592 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2593
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2594 default:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2595 print_nd_array <ComplexNDArray, Complex, ComplexMatrix>
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2596 (os, nda, pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2597 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2598 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2599 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2600
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2601 void
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2602 octave_print_internal (std::ostream& os, bool d, bool pr_as_read_syntax)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2603 {
21583
d5963a6e29c2 Use integer output formatting for logicals (bug #47607)
Mike Miller <mtmiller@octave.org>
parents: 21568
diff changeset
2604 octave_print_internal (os, octave_uint8 (d), pr_as_read_syntax);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2605 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2606
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2607 // 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
2608
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2609 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2610 octave_print_internal (std::ostream& os, float d, bool pr_as_read_syntax)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2611 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2612 octave_print_internal (os, double (d), pr_as_read_syntax);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2613 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2614
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2615 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2616 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
2617 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
2618 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2619 octave_print_internal (os, Matrix (m), pr_as_read_syntax, extra_indent);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2620 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2621
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2622 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2623 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
2624 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
2625 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2626 octave_print_internal (os, DiagMatrix (m), pr_as_read_syntax, extra_indent);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2627 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2628
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2629 void
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2630 octave_print_internal (std::ostream& os, const FloatNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2631 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
2632 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2633 octave_print_internal (os, NDArray (nda), pr_as_read_syntax, extra_indent);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2634 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2635
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2636 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2637 octave_print_internal (std::ostream& os, const FloatComplex& c,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2638 bool pr_as_read_syntax)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2639 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2640 octave_print_internal (os, Complex (c), pr_as_read_syntax);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2641 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2642
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2643 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2644 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
2645 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
2646 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2647 octave_print_internal (os, ComplexMatrix (cm), pr_as_read_syntax,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2648 extra_indent);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2649 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2650
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2651 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2652 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
2653 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2654 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2655 octave_print_internal (os, ComplexDiagMatrix (cm), pr_as_read_syntax,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2656 extra_indent);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2657 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2658
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2659 void
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2660 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2661 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
2662 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2663 octave_print_internal (os, ComplexNDArray (nda), pr_as_read_syntax,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2664 extra_indent);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2665 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2666
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2667 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2668 octave_print_internal (std::ostream& os, const Range& r,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2669 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2670 {
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2671 double base = r.base ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2672 double increment = r.inc ();
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2673 double limit = r.limit ();
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20172
diff changeset
2674 octave_idx_type num_elem = r.numel ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2675
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2676 if (plus_format && ! pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2677 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2678 for (octave_idx_type i = 0; i < num_elem; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2679 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2680 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2681
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2682 double val = base + i * increment;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2683
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2684 pr_plus_format (os, val);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2685 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2686 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2687 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2688 {
10987
eec74ee00b32 eliminate some GCC warnings
John W. Eaton <jwe@octave.org>
parents: 10846
diff changeset
2689 int fw = 0;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
2690 double scale = 1.0;
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
2691 set_format (r, fw, scale);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2692
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2693 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2694 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2695 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2696 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2697 os << base << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2698 if (increment != 1.0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2699 os << increment << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2700 os << limit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2701 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2702 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2703 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2704 pr_float (os, base, fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2705 os << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2706 if (increment != 1.0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2707 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2708 pr_float (os, increment, fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2709 os << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2710 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2711 pr_float (os, limit, fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2712 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2713 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2714 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2715 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2716 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2717
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2718 int column_width = fw + 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2719 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
2720 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
2721
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2722 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2723 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2724 os << r;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2725 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2726 }
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 octave_idx_type inc = num_elem;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2729 if (total_width > max_width && Vsplit_long_rows)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2730 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2731 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2732 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2733 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2734 }
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 max_width -= extra_indent;
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 (max_width < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2739 max_width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2740
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2741 pr_scale_header (os, scale);
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 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2744 while (col < num_elem)
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 octave_idx_type lim = col + inc < num_elem ? col + inc : num_elem;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2747
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2748 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
2749 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2750
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2751 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2752
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2753 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
2754 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2755 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2756
16169
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2757 double val;
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2758 if (i == 0)
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2759 val = base;
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2760 else
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2761 val = base + i * increment;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2762
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2763 if (i == num_elem - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2764 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2765 // See the comments in Range::matrix_value.
16169
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2766 if ((increment > 0 && val >= limit)
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2767 || (increment < 0 && val <= limit))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2768 val = limit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2769 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2770
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2771 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2772
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2773 pr_float (os, val, fw, scale);
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2776 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2777 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2778 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2779 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2780 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2781
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2782 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2783 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
2784 bool pr_as_read_syntax,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2785 int extra_indent)
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2786 {
21583
d5963a6e29c2 Use integer output formatting for logicals (bug #47607)
Mike Miller <mtmiller@octave.org>
parents: 21568
diff changeset
2787 uint8NDArray tmp (bm);
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2788 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
2789 }
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2790
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2791 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2792 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
2793 bool pr_as_read_syntax,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2794 int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2795 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2796 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2797 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2798 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2799 case 2:
19317
25f535b90e52 Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.
Carnë Draug <carandraug@octave.org>
parents: 19255
diff changeset
2800 octave_print_internal (os, boolMatrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2801 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2802 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2803
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2804 default:
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2805 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
2806 boolMatrix> (os, nda, pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2807 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2808 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2809 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2810
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2811 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2812 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
2813 bool pr_as_read_syntax,
21066
258c787cd9ce maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents: 20946
diff changeset
2814 int /* FIXME: extra_indent */,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2815 bool pr_as_string)
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2816 {
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2817 if (pr_as_string)
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2818 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2819 octave_idx_type nstr = chm.rows ();
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2820
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2821 if (pr_as_read_syntax && nstr > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2822 os << "[ ";
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2823
2907
8bb31a2b480b [project @ 1997-04-30 05:01:46 by jwe]
jwe
parents: 2903
diff changeset
2824 if (nstr != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2825 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2826 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
2827 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2828 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2829
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2830 std::string row = chm.row_as_string (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2831
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2832 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2833 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2834 os << "\"" << undo_string_escapes (row) << "\"";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2835
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2836 if (i < nstr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2837 os << "; ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2838 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2839 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2840 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2841 os << row;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2842
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2843 if (i < nstr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2844 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2845 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2846 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2847 }
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2848
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2849 if (pr_as_read_syntax && nstr > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2850 os << " ]";
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2851 }
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2852 else
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2853 {
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2854 os << "sorry, printing char matrices not implemented yet\n";
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2855 }
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2856 }
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2857
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2858 void
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2859 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
2860 bool pr_as_read_syntax, int extra_indent,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2861 bool pr_as_string)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2862 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2863 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2864 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2865 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2866 case 2:
19318
6c9ea5be96bf Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents: 19317
diff changeset
2867 octave_print_internal (os, charMatrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2868 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
2869 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2870
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2871 default:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2872 print_nd_array <charNDArray, char, charMatrix> (os, nda,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2873 pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2874 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2875 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2876 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2877
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2878 void
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2879 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
2880 bool pr_as_read_syntax, int extra_indent)
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2881 {
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9643
diff changeset
2882 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
2883
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2884 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
2885 }
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2886
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2887 void
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9643
diff changeset
2888 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
2889 bool pr_as_read_syntax, int /* extra_indent */)
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2890 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2891 // 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
2892 // 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
2893
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2894 if (nda.is_empty ())
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2895 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
2896 else if (nda.numel () == 1)
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2897 {
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2898 os << nda(0);
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2899 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2900 else
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2901 {
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2902 int ndims = nda.ndims ();
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2903
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2904 dim_vector dims = nda.dims ();
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2905
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2906 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
2907
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2908 octave_idx_type m = 1;
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2909
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2910 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2911 m *= dims(i);
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2912
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2913 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2914 octave_idx_type nc = dims(1);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2915
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2916 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
2917 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2918 std::string nm = "ans";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2919
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2920 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2921 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2922 nm += "(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2923
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2924 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2925
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2926 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2927 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2928 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2929
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2930 if (k < ndims - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2931 buf << ",";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2932 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2933 buf << ")";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2934 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2935
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2936 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2937 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2938
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2939 Array<idx_vector> idx (dim_vector (ndims, 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2940
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2941 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2942 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2943
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2944 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2945 idx(k) = idx_vector (ra_idx(k));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2946
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2947 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
2948
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2949 // 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
2950 // in neatly aligned columns...
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2951
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2952 octave_idx_type n_rows = page.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2953 octave_idx_type n_cols = page.cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2954
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2955 os << nm << " =\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2956 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2957 os << "\n";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2958
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2959 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
2960 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2961 for (octave_idx_type jj = 0; jj < n_cols; jj++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2962 os << " " << page(ii,jj);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2963
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2964 os << "\n";
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
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2967 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2968 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2969
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2970 if (i < m)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2971 increment_index (ra_idx, dims, 2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2972 }
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2973 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2974 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2975
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2976 template <typename T>
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2977 class
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2978 octave_print_conv
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2979 {
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2980 public:
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2981 typedef T print_conv_type;
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2982 };
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2983
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2984 #define PRINT_CONV(T1, T2) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2985 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2986 class \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2987 octave_print_conv<T1> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2988 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2989 public: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2990 typedef T2 print_conv_type; \
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2991 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2992
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2993 PRINT_CONV (octave_int8, octave_int16);
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2994 PRINT_CONV (octave_uint8, octave_uint16);
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2995
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2996 #undef PRINT_CONV
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2997
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2998 template <typename T>
6018
bda649f500bd [project @ 2006-10-02 17:23:18 by jwe]
jwe
parents: 6015
diff changeset
2999 /* static */ inline void
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3000 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
3001 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
3002 size_t sz = d.byte_size ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
3003 const unsigned char * tmpi = d.iptr ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3004
5544
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
3005 // Unless explicitly asked for, always print in big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
3006 // format for hex and bit formats.
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
3007 //
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
3008 // {bit,hex}_format == 1: print big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
3009 // {bit,hex}_format == 2: print native
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
3010
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3011 if (hex_format)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3012 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3013 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3014
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3015 os.flags (std::ios::right | std::ios::hex);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3016
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
3017 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
3018 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3019 for (size_t i = 0; i < sz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3020 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
3021 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3022 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3023 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3024 for (int i = sz - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3025 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
3026 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3027 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3028 else if (bit_format)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3029 {
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
3030 if (octave::mach_info::words_big_endian ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3031 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3032 for (size_t i = 0; i < sz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3033 PRINT_CHAR_BITS (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3034 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3035 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3036 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3037 if (bit_format > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3038 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3039 for (size_t i = 0; i < sz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3040 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]);
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 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3043 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3044 for (int i = sz - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3045 PRINT_CHAR_BITS (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3046 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3047 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3048 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3049 else
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3050 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3051 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3052
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3053 os << std::setw (fw)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3054 << 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
3055
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3056 if (bank_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3057 os << ".00";
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3058 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3059 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3060
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3061 // FIXME: all this mess with abs is an attempt to avoid seeing
6120
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3062 //
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3063 // warning: comparison of unsigned expression < 0 is always false
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3064 //
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3065 // from GCC. Isn't there a better way?
6120
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3066
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
3067 template <typename T>
6018
bda649f500bd [project @ 2006-10-02 17:23:18 by jwe]
jwe
parents: 6015
diff changeset
3068 /* static */ inline T
6008
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
3069 abs (T x)
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
3070 {
6120
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3071 return x < 0 ? -x : x;
6008
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
3072 }
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
3073
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3074 #define INSTANTIATE_ABS(T) \
12414
1cf28ef2bb88 small changes for GCC 4.6
John W. Eaton <jwe@octave.org>
parents: 12192
diff changeset
3075 template /* static */ T abs (T)
6120
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3076
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3077 INSTANTIATE_ABS(signed char);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3078 INSTANTIATE_ABS(short);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3079 INSTANTIATE_ABS(int);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3080 INSTANTIATE_ABS(long);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3081 INSTANTIATE_ABS(long long);
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3082
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3083 #define SPECIALIZE_UABS(T) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3084 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3085 /* static */ inline unsigned T \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3086 abs (unsigned T x) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3087 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3088 return x; \
6120
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3089 }
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3090
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3091 SPECIALIZE_UABS(char)
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3092 SPECIALIZE_UABS(short)
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3093 SPECIALIZE_UABS(int)
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3094 SPECIALIZE_UABS(long)
ba9db42a1fe0 [project @ 2006-10-28 02:45:48 by jwe]
jwe
parents: 6109
diff changeset
3095 SPECIALIZE_UABS(long long)
6008
0f5bc819fdb8 [project @ 2006-09-27 15:34:28 by jwe]
jwe
parents: 5945
diff changeset
3096
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3097 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3098 pr_int (std::ostream&, const octave_int8&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3099
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3100 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3101 pr_int (std::ostream&, const octave_int16&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3102
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3103 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3104 pr_int (std::ostream&, const octave_int32&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3105
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3106 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3107 pr_int (std::ostream&, const octave_int64&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3108
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3109 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3110 pr_int (std::ostream&, const octave_uint8&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3111
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3112 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3113 pr_int (std::ostream&, const octave_uint16&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3114
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3115 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3116 pr_int (std::ostream&, const octave_uint32&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3117
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3118 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3119 pr_int (std::ostream&, const octave_uint64&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3120
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
3121 template <typename T>
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3122 void
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3123 octave_print_internal_template (std::ostream& os, const octave_int<T>& val,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3124 bool)
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3125 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3126 if (plus_format)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3127 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3128 pr_plus_format (os, val);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3129 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3130 else
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3131 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3132 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3133 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
3134 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3135 pr_int (os, val);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3136 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3137 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3138
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3139 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3140 OCTINTERP_API void \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3141 octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3142 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3143 octave_print_internal_template (os, val, dummy); \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3144 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3145
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3146 PRINT_INT_SCALAR_INTERNAL (int8_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3147 PRINT_INT_SCALAR_INTERNAL (uint8_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3148 PRINT_INT_SCALAR_INTERNAL (int16_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3149 PRINT_INT_SCALAR_INTERNAL (uint16_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3150 PRINT_INT_SCALAR_INTERNAL (int32_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3151 PRINT_INT_SCALAR_INTERNAL (uint32_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3152 PRINT_INT_SCALAR_INTERNAL (int64_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3153 PRINT_INT_SCALAR_INTERNAL (uint64_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3154
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
3155 template <typename T>
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3156 /* static */ inline void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3157 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
3158 bool pr_as_read_syntax, int extra_indent)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3159 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3160 // 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
3161 // 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
3162
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3163 if (nda.is_empty ())
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3164 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
3165 else if (nda.numel () == 1)
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3166 octave_print_internal_template (os, nda(0), pr_as_read_syntax);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3167 else if (plus_format && ! pr_as_read_syntax)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3168 {
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3169 int ndims = nda.ndims ();
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3170
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3171 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
3172
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3173 dim_vector dims = nda.dims ();
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3174
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3175 octave_idx_type m = 1;
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3176
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3177 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3178 m *= dims(i);
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3179
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3180 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3181 octave_idx_type nc = dims(1);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3182
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3183 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
3184 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3185 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3186 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3187 std::string nm = "ans(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3188
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3189 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3190
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3191 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3192 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3193 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3194
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3195 if (k < ndims - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3196 buf << ",";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3197 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3198 buf << ")";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3199 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3200
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3201 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3202
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3203 os << nm << " =\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3204 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3205 os << "\n";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3206 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3207
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3208 Array<idx_vector> idx (dim_vector (ndims, 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3209
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3210 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3211 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3212
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3213 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3214 idx(k) = idx_vector (ra_idx(k));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3215
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3216 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
3217
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3218 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
3219 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3220 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
3221 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3222 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3223
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3224 pr_plus_format (os, page(ii,jj));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3225 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3226
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3227 if ((ii < nr - 1) || (i < m -1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3228 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3229 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3230
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3231 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3232 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3233 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3234 increment_index (ra_idx, dims, 2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3235 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3236 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3237 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3238 else
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3239 {
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3240 int ndims = nda.ndims ();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3241
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3242 dim_vector dims = nda.dims ();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3243
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3244 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
3245
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3246 octave_idx_type m = 1;
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3247
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3248 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3249 m *= dims(i);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3250
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3251 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3252 octave_idx_type nc = dims(1);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3253
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3254 int fw = 0;
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3255 if (hex_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3256 fw = 2 * nda(0).byte_size ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3257 else if (bit_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3258 fw = nda(0).nbits ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3259 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3260 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3261 bool isneg = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3262 int digits = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3263
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3264 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
3265 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3266 int new_digits
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3267 = static_cast<int>
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
3268 (std::floor (log10 (double (abs (nda(i).value ()))) + 1.0));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3269
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3270 if (new_digits > digits)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3271 digits = new_digits;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3272
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3273 if (! isneg)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3274 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
3275 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3276
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3277 fw = digits + isneg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3278 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3279
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3280 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
3281 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
3282 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
3283 octave_idx_type inc = nc;
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3284 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
3285 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3286 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3287 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3288 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3289 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
3290
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
3291 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
3292 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3293 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3294 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3295 std::string nm = "ans(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3296
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3297 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3298
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3299 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3300 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3301 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3302
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3303 if (k < ndims - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3304 buf << ",";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3305 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3306 buf << ")";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3307 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3308
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3309 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3310
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3311 os << nm << " =\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3312 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3313 os << "\n";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3314 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3315
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3316 Array<idx_vector> idx (dim_vector (ndims, 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3317
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3318 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3319 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3320
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3321 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3322 idx(k) = idx_vector (ra_idx(k));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3323
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3324 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
3325
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3326 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3327 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3328 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3329 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3330
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3331 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
3332 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3333 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
3334 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3335 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3336 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3337 os << typename octave_print_conv<T>::print_conv_type (page(ii,jj));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3338 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3339 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3340 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3341
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3342 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3343 os << "]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3344 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3345 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3346 {
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3347 octave_preserve_stream_state stream_state (os);
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3348
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3349 octave_idx_type n_rows = page.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3350 octave_idx_type n_cols = page.cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3351
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3352 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
3353 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3354 octave_idx_type lim = col + inc < n_cols ? col + inc : n_cols;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3355
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3356 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
3357 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3358
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3359 for (octave_idx_type ii = 0; ii < n_rows; ii++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3360 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3361 os << std::setw (extra_indent) << "";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3362
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3363 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
3364 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3365 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3366 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3367 pr_int (os, page(ii,jj), fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3368 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3369 if ((ii < n_rows - 1) || (i < m -1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3370 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3371 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3372 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3373 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3374
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3375 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3376 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3377 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3378 increment_index (ra_idx, dims, 2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3379 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3380 }
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3381 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3382 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3383
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3384 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3385 OCTINTERP_API void \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3386 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
3387 bool pr_as_read_syntax, int extra_indent) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3388 { \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3389 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
3390 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3391
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3392 PRINT_INT_ARRAY_INTERNAL (octave_int8)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3393 PRINT_INT_ARRAY_INTERNAL (octave_uint8)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3394 PRINT_INT_ARRAY_INTERNAL (octave_int16)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3395 PRINT_INT_ARRAY_INTERNAL (octave_uint16)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3396 PRINT_INT_ARRAY_INTERNAL (octave_int32)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3397 PRINT_INT_ARRAY_INTERNAL (octave_uint32)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3398 PRINT_INT_ARRAY_INTERNAL (octave_int64)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3399 PRINT_INT_ARRAY_INTERNAL (octave_uint64)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3400
8012
63dbb85452cc fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents: 7896
diff changeset
3401 void
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
3402 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
3403 {
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
3404 panic_impossible ();
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3405 }
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3406
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3407 void
19620
a1d172bfcb2f eliminate some unused variable and typedef warnings
John W. Eaton <jwe@octave.org>
parents: 19367
diff changeset
3408 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
3409 {
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3410 panic_impossible ();
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3411 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3412
20915
a3359fe50966 remove unused nargout variables
John W. Eaton <jwe@octave.org>
parents: 20909
diff changeset
3413 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
3414 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
3415 @deftypefn {} {} rats (@var{x}, @var{len})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3416 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
3417
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3418 The string can be converted back into a matrix as follows:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3419
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3420 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3421 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3422 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
3423 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
3424 @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
3425 @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
3426
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3427 The optional second argument defines the maximum length of the string
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3428 representing the elements of @var{x}. By default @var{len} is 9.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3429
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3430 If the length of the smallest possible rational approximation exceeds
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3431 @var{len}, an asterisk (*) padded with spaces will be returned instead.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3432 @seealso{format, rat}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3433 @end deftypefn */)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3434 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3435 int nargin = args.length ();
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3436
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20897
diff changeset
3437 if (nargin < 1 || nargin > 2)
7896
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3438 print_usage ();
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3439
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3440 octave_value arg = args(0);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3441
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3442 if (! arg.is_numeric_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3443 error ("rats: X must be numeric");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3444
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
3445 octave::unwind_protect frame;
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3446
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3447 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
3448
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3449 rat_string_len = 9;
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3450 if (nargin == 2)
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3451 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
3452
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3453 frame.protect_var (rat_format);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3454
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3455 rat_format = true;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3456
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3457 std::ostringstream buf;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3458 arg.print (buf);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3459 std::string s = buf.str ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3460
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3461 std::list<std::string> lst;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3462
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3463 size_t n = 0;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3464 size_t s_len = s.length ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3465
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3466 while (n < s_len)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3467 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3468 size_t m = s.find ('\n', n);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3469
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3470 if (m == std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3471 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3472 lst.push_back (s.substr (n));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3473 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3474 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3475 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3476 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3477 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
3478 n = m + 1;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3479 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3480 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3481
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3482 return ovl (string_vector (lst));
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3483 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3484
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3485 DEFUN (disp, 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
3486 doc: /* -*- texinfo -*-
24764
36ca11f78553 Document second calling form of disp().
Rik <rik@octave.org>
parents: 23219
diff changeset
3487 @deftypefn {} {} disp (@var{x})
36ca11f78553 Document second calling form of disp().
Rik <rik@octave.org>
parents: 23219
diff changeset
3488 @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
3489 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
3490
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3491 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
3492
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3493 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3494 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3495 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
3496
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3497 @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
3498 @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
3499 @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
3500 @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
3501
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3502 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3503 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
3504
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3505 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
3506 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
3507 @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
3508 @end deftypefn */)
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3509 {
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20897
diff changeset
3510 if (args.length () != 1)
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3511 print_usage ();
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3512
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3513 octave_value_list retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3514
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3515 octave_value arg = args(0);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3516
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3517 if (nargout == 0)
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3518 arg.print (octave_stdout);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3519 else
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3520 {
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3521 std::ostringstream buf;
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3522 arg.print (buf);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3523 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
3524 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3525
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3526 return retval;
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3527 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3528
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3529 DEFUN (fdisp, 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
3530 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
3531 @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
3532 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
3533
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3534 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
3535
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3536 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3537 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3538 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
3539
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3540 @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
3541 @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
3542 @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
3543 @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
3544
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3545 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3546 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
3547 @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
3548 @end deftypefn */)
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3549 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20801
diff changeset
3550 if (args.length () != 2)
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3551 print_usage ();
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3552
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3553 int fid = octave_stream_list::get_file_number (args(0));
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3554
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3555 octave_stream os = octave_stream_list::lookup (fid, "fdisp");
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3556
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3557 std::ostream *osp = os.output_stream ();
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3558
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3559 octave_value arg = args(1);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3560
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3561 if (osp)
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3562 arg.print (*osp);
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3563 else
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3564 error ("fdisp: stream FID not open for writing");
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3565
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
3566 return ovl ();
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3567 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3568
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3569 /*
9629
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3570 %!test
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3571 %! format short
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3572 %! fd = tmpfile ();
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3573 %! for r = [0, Inf -Inf, NaN]
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3574 %! for i = [0, Inf -Inf, NaN]
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3575 %! fdisp (fd, complex (r, i));
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3576 %! endfor
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3577 %! endfor
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3578 %! fclose (fd);
13129
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3579
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3580 %!test
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3581 %! foo.real = pi * ones (3,20,3);
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3582 %! foo.complex = pi * ones (3,20,3) + 1i;
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3583 %! foo.char = repmat ("- Hello World -", [3, 20]);
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3584 %! foo.cell = {foo.real, foo.complex, foo.char};
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3585 %! fields = fieldnames (foo);
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
3586 %! for f = 1:numel (fields)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
3587 %! format loose;
13129
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3588 %! loose = disp (foo.(fields{f}));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
3589 %! format compact;
13129
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3590 %! compact = disp (foo.(fields{f}));
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3591 %! expected = strrep (loose, "\n\n", "\n");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
3592 %! assert (expected, compact);
13129
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3593 %! endfor
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3594 */
9629
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3595
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3596 static void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3597 init_format_state (void)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3598 {
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3599 free_format = false;
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3600 plus_format = false;
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3601 rat_format = false;
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3602 bank_format = false;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
3603 hex_format = 0;
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
3604 bit_format = 0;
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3605 Vcompact_format = false;
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3606 print_e = false;
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3607 print_big_e = false;
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3608 print_g = false;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3609 print_eng = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3610 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3611
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3612 static void
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3613 set_output_prec_and_fw (int prec, int fw)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3614 {
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21547
diff changeset
3615 Voutput_precision = prec;
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3616 Voutput_max_field_width = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3617 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3618
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3619 static std::string format_string ("short");
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3620
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3621 static void
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3622 set_format_style (int argc, const string_vector& argv)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3623 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3624 int idx = 1;
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3625 std::string format;
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3626
1899
2f19333b1e72 [project @ 1996-02-09 17:46:58 by jwe]
jwe
parents: 1884
diff changeset
3627 if (--argc > 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3628 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3629 std::string arg = argv[idx++];
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3630 format = arg;
2584
5e41d9c42283 [project @ 1996-12-10 09:39:44 by jwe]
jwe
parents: 2522
diff changeset
3631
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3632 if (arg == "short")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3633 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3634 if (--argc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3635 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3636 arg = argv[idx++];
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3637 format.append (arg);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3638
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3639 if (arg == "e")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3640 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3641 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3642 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3643 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3644 else if (arg == "E")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3645 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3646 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3647 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3648 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3649 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3650 else if (arg == "g")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3651 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3652 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3653 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3654 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3655 else if (arg == "G")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3656 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3657 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3658 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3659 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3660 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3661 else if (arg == "eng")
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3662 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3663 init_format_state ();
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3664 print_eng = true;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3665 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3666 else
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
3667 error ("format: unrecognized option 'short %s'", arg.c_str ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3668 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3669 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3670 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3671
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3672 set_output_prec_and_fw (5, 10);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3673 }
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3674 else if (arg == "shorte")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3675 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3676 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3677 print_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3678 set_output_prec_and_fw (5, 10);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3679 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3680 else if (arg == "shortE")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3681 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3682 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3683 print_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3684 print_big_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3685 set_output_prec_and_fw (5, 10);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3686 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3687 else if (arg == "shortg")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3688 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3689 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3690 print_g = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3691 set_output_prec_and_fw (5, 10);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3692 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3693 else if (arg == "shortG")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3694 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3695 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3696 print_g = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3697 print_big_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3698 set_output_prec_and_fw (5, 10);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3699 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3700 else if (arg == "shortEng")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3701 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3702 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3703 print_eng = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3704 set_output_prec_and_fw (5, 10);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3705 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3706 else if (arg == "long")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3707 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3708 if (--argc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3709 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3710 arg = argv[idx++];
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3711 format.append (arg);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3712
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3713 if (arg == "e")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3714 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3715 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3716 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3717 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3718 else if (arg == "E")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3719 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3720 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3721 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3722 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3723 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3724 else if (arg == "g")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3725 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3726 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3727 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3728 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3729 else if (arg == "G")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3730 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3731 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3732 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3733 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3734 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3735 else if (arg == "eng")
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3736 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3737 init_format_state ();
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3738 print_eng = true;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3739 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3740 else
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
3741 error ("format: unrecognized option 'long %s'", arg.c_str ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3742 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3743 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3744 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3745
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3746 set_output_prec_and_fw (15, 20);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3747 }
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3748 else if (arg == "longe")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3749 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3750 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3751 print_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3752 set_output_prec_and_fw (15, 20);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3753 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3754 else if (arg == "longE")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3755 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3756 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3757 print_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3758 print_big_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3759 set_output_prec_and_fw (15, 20);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3760 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3761 else if (arg == "longg")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3762 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3763 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3764 print_g = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3765 set_output_prec_and_fw (15, 20);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3766 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3767 else if (arg == "longG")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3768 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3769 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3770 print_g = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3771 print_big_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3772 set_output_prec_and_fw (15, 20);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3773 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3774 else if (arg == "longEng")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3775 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3776 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3777 print_eng = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3778 set_output_prec_and_fw (15, 20);
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3779 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3780 else if (arg == "hex")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3781 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3782 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3783 hex_format = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3784 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3785 else if (arg == "native-hex")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3786 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3787 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3788 hex_format = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3789 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3790 else if (arg == "bit")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3791 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3792 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3793 bit_format = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3794 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3795 else if (arg == "native-bit")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3796 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3797 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3798 bit_format = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3799 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3800 else if (arg == "+" || arg == "plus")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3801 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3802 if (--argc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3803 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3804 arg = argv[idx++];
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3805 format.append (arg);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3806
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3807 if (arg.length () == 3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3808 plus_format_chars = arg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3809 else
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
3810 error ("format: invalid option for plus format");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3811 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3812 else
19232
97eea1e2d9ff pr-output.cc: fix default chars for "format +" for Matlab compatibility
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
3813 plus_format_chars = "+- ";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3814
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3815 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3816 plus_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3817 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3818 else if (arg == "rat")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3819 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3820 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3821 rat_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3822 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3823 else if (arg == "bank")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3824 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3825 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3826 bank_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3827 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3828 else if (arg == "free")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3829 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3830 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3831 free_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3832 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3833 else if (arg == "none")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3834 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3835 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3836 free_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3837 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3838 else if (arg == "compact")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3839 {
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3840 Vcompact_format = true;
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3841 return;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3842 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3843 else if (arg == "loose")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3844 {
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3845 Vcompact_format = false;
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3846 return;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3847 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3848 else
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
3849 error ("format: unrecognized format state '%s'", arg.c_str ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3850 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3851 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3852 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3853 init_format_state ();
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3854 set_output_prec_and_fw (5, 10);
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3855 format = std::string ("short");
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3856 }
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3857
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3858 format_string = format;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3859 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3860
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8625
diff changeset
3861 DEFUN (format, 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
3862 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
3863 @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
3864 @deftypefnx {} {} format options
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3865 Reset or specify the format of the output produced by @code{disp} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3866 Octave's normal echoing mechanism.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3867
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3868 This command only affects the display of numbers but not how they are stored
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3869 or computed. To change the internal representation from the default double
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3870 use one of the conversion functions such as @code{single}, @code{uint8},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3871 @code{int64}, etc.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3872
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3873 By default, Octave displays 5 significant digits in a human readable form
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3874 (option @samp{short} paired with @samp{loose} format for matrices).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3875 If @code{format} is invoked without any options, this default format
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3876 is restored.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3877
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3878 Valid formats for floating point numbers are listed in the following
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3879 table.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3880
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3881 @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
3882 @item short
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3883 Fixed point format with 5 significant figures in a field that is a maximum
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3884 of 10 characters wide. (default).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3885
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3886 If Octave is unable to format a matrix so that columns line up on the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3887 decimal point and all numbers fit within the maximum field width then
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3888 it switches to an exponential @samp{e} format.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3889
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3890 @item long
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3891 Fixed point format with 15 significant figures in a field that is a maximum
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3892 of 20 characters wide.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3893
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3894 As with the @samp{short} format, Octave will switch to an exponential
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3895 @samp{e} format if it is unable to format a matrix properly using the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3896 current format.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3897
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3898 @item short e
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3899 @itemx long e
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3900 Exponential format. The number to be represented is split between a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3901 mantissa and an exponent (power of 10). The mantissa has 5 significant
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3902 digits in the short format and 15 digits in the long format. 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
3903 with the @samp{short e} format, @code{pi} 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
3904 @code{3.1416e+00}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3905
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3906 @item short E
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3907 @itemx long E
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3908 Identical to @samp{short e} or @samp{long e} but displays an uppercase
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3909 @samp{E} to indicate the exponent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3910 For example, with the @samp{long E} format, @code{pi} 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
3911 @code{3.14159265358979E+00}.
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 @item short g
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3914 @itemx long g
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3915 Optimally choose between fixed point and exponential format based on
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3916 the magnitude of the number.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3917 For example, with the @samp{short g} format,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3918 @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
3919
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3920 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3921 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3922 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3923
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3924 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
3925 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
3926 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
3927 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
3928 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
3929 @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
3930 @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
3931
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3932 @item short eng
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3933 @itemx long eng
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3934 Identical to @samp{short e} or @samp{long e} but displays the value
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3935 using an engineering format, where the exponent is divisible by 3. For
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3936 example, with the @samp{short eng} format, @code{10 * pi} 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
3937 @code{31.4159e+00}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3938
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3939 @item long G
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3940 @itemx short G
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3941 Identical to @samp{short g} or @samp{long g} but displays an uppercase
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3942 @samp{E} to indicate the exponent.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3943
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3944 @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
3945 @itemx none
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3946 Print output in free format, without trying to line up columns of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3947 matrices on the decimal point. This also causes complex numbers to be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3948 formatted as numeric pairs like this @samp{(0.60419, 0.60709)} instead
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3949 of like this @samp{0.60419 + 0.60709i}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3950 @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
3951
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3952 The following formats affect all numeric output (floating point and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3953 integer types).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3954
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3955 @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
3956 @item "+"
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3957 @itemx "+" @var{chars}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3958 @itemx plus
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3959 @itemx plus @var{chars}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3960 Print a @samp{+} symbol for matrix elements greater than zero, a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3961 @samp{-} symbol for elements less than zero and a space for zero matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3962 elements. This format can be very useful for examining the structure
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3963 of a large sparse matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3964
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3965 The optional argument @var{chars} specifies a list of 3 characters to use
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3966 for printing values greater than zero, less than zero and equal to zero.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3967 For example, with the @samp{"+" "+-."} format,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3968 @code{[1, 0, -1; -1, 0, 1]} 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
3969
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3970 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3971 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3972 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3973
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3974 +.-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3975 -.+
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3976 @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
3977 @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
3978
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3979 @item bank
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3980 Print in a fixed format with two digits to the right of the decimal
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3981 point.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3982
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3983 @item native-hex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3984 Print the hexadecimal representation of numbers as they are stored in
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3985 memory. For example, on a workstation which stores 8 byte real values
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3986 in IEEE format with the least significant byte first, the value of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3987 @code{pi} when printed in @code{native-hex} format is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3988 @code{400921fb54442d18}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3989
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3990 @item hex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3991 The same as @code{native-hex}, but always print the most significant
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3992 byte first.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3993
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3994 @item native-bit
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3995 Print the bit representation of numbers as stored in memory.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3996 For example, the value of @code{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
3997
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3998 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3999 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4000 01000000000010010010000111111011
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4001 01010100010001000010110100011000
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4002 @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
4003 @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
4004
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4005 (shown here in two 32 bit sections for typesetting purposes) when
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4006 printed in native-bit format on a workstation which stores 8 byte real
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4007 values in IEEE format with the least significant byte first.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4008
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4009 @item bit
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4010 The same as @code{native-bit}, but always print the most significant
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4011 bits first.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4012
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4013 @item rat
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4014 Print a rational approximation, i.e., values are approximated
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4015 as the ratio of small integers.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4016 For example, with the @samp{rat} format,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4017 @code{pi} is displayed as @code{355/113}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4018 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4019
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4020 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
4021
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4022 @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
4023 @item compact
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4024 Remove blank lines around column number labels and between
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4025 matrices producing more compact output with more data per page.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4026
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4027 @item loose
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4028 Insert blank lines above and below column number labels and between matrices
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4029 to produce a more readable output with less data per page. (default).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4030 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4031 @seealso{fixed_point_format, output_max_field_width, output_precision, split_long_rows, print_empty_dimensions, rats}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4032 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
4033 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
4034 int argc = args.length () + 1;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
4035
1968
a2e206524aa0 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents: 1961
diff changeset
4036 string_vector argv = args.make_argv ("format");
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
4037
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
4038 set_format_style (argc, argv);
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
4039
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
4040 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
4041 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
4042
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4043 DEFUN (__compactformat__, 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
4044 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
4045 @deftypefn {} {@var{val} =} __compactformat__ ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4046 @deftypefnx {} {} __compactformat__ (@var{TRUE|FALSE})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4047 Undocumented internal function
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4048 @end deftypefn */)
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4049 {
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4050 return SET_INTERNAL_VARIABLE (compact_format);
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4051 }
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4052
18801
307a67b04253 pr-output.cc: Clean up unused parameter compilation warning.
Rik <rik@octave.org>
parents: 18735
diff changeset
4053 DEFUN (__formatstring__, , ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4054 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
4055 @deftypefn {} {@var{val} =} __formatstring__ ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4056 Undocumented internal function
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4057 @end deftypefn */)
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4058 {
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4059 return ovl (format_string);
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4060 }
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
4061
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4062 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
4063 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
4064 @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
4065 @deftypefnx {} {@var{old_val} =} fixed_point_format (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4066 @deftypefnx {} {} fixed_point_format (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4067 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
4068 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
4069
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4070 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
4071 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
4072 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
4073
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4074 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4075 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4076 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
4077 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4078
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4079 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
4080
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4081 0.00000
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4082 0.00003
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4083 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
4084 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
4085 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
4086 @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
4087 @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
4088
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4089 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4090 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
4091 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
4092 @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
4093
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4094 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
4095 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
4096 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
4097 @seealso{format, output_max_field_width, output_precision}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4098 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4099 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4100 return SET_INTERNAL_VARIABLE (fixed_point_format);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4101 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4102
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4103 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
4104 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
4105 @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
4106 @deftypefnx {} {@var{old_val} =} print_empty_dimensions (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4107 @deftypefnx {} {} print_empty_dimensions (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4108 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
4109 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
4110
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4111 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
4112
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4113 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4114 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
4115 @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
4116
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4117 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4118 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
4119
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4120 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4121 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
4122 @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
4123
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4124 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
4125 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
4126 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
4127 @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
4128 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4129 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4130 return SET_INTERNAL_VARIABLE (print_empty_dimensions);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4131 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4132
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4133 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
4134 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
4135 @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
4136 @deftypefnx {} {@var{old_val} =} split_long_rows (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4137 @deftypefnx {} {} split_long_rows (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4138 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
4139 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
4140
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4141 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
4142 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
4143 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
4144 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
4145
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4146 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4147 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4148 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
4149 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4150
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4151 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
4152
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4153 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
4154 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
4155
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4156 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
4157
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4158 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
4159 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
4160 @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
4161 @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
4162
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4163 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
4164 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
4165 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
4166 @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
4167 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4168 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4169 return SET_INTERNAL_VARIABLE (split_long_rows);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4170 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4171
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4172 DEFUN (output_max_field_width, 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
4173 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
4174 @deftypefn {} {@var{val} =} output_max_field_width ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4175 @deftypefnx {} {@var{old_val} =} output_max_field_width (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4176 @deftypefnx {} {} output_max_field_width (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4177 Query or set the internal variable that specifies the maximum width
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4178 of a numeric output field.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4179
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4180 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
4181 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
4182 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
4183 @seealso{format, fixed_point_format, output_precision}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4184 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4185 {
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
4186 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_max_field_width, 0,
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
4187 std::numeric_limits<int>::max ());
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4188 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4189
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4190 DEFUN (output_precision, 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
4191 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
4192 @deftypefn {} {@var{val} =} output_precision ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4193 @deftypefnx {} {@var{old_val} =} output_precision (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4194 @deftypefnx {} {} output_precision (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4195 Query or set the internal variable that specifies the minimum number of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4196 significant figures to display for numeric output.
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 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
4199 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
4200 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
4201 @seealso{format, fixed_point_format, output_max_field_width}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4202 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4203 {
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
4204 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, -1,
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
4205 std::numeric_limits<int>::max ());
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4206 }