Mercurial > octave
annotate libinterp/corefcn/pr-output.cc @ 21724:aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
* configure.ac, Doxyfile.in, make_int.cc, Backend.cc, BaseControl.cc,
ButtonControl.cc, Canvas.cc, CheckBoxControl.cc, Container.cc,
ContextMenu.cc, EditControl.cc, Figure.cc, FigureWindow.cc,
GLCanvas.cc, KeyMap.cc, ListBoxControl.cc, Logger.cc, Menu.cc,
MouseModeActionGroup.cc, Object.cc, ObjectFactory.cc,
ObjectProxy.cc, Panel.cc, PopupMenuControl.cc, PushButtonControl.cc,
PushTool.cc, QtHandlesUtils.cc, RadioButtonControl.cc,
SliderControl.cc, TextControl.cc, TextEdit.cc,
ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, __init_qt__.cc,
annotation-dialog.cc, gl-select.cc, module.mk, color-picker.cc,
dialog.cc, documentation-dock-widget.cc, files-dock-widget.cc,
find-files-dialog.cc, find-files-model.cc, history-dock-widget.cc,
liboctgui-build-info.in.cc, file-editor-tab.cc, file-editor.cc,
find-dialog.cc, marker.cc, marker.h, octave-qscintilla.cc,
octave-txt-lexer.cc, main-window.cc, octave-cmd.cc,
octave-dock-widget.cc, octave-gui.cc, octave-interpreter.cc,
octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc,
settings-dialog.cc, shortcut-manager.cc, terminal-dock-widget.cc,
thread-manager.cc, welcome-wizard.cc, workspace-model.cc,
workspace-view.cc, build-env.in.cc, Cell.cc, __contourc__.cc,
__dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc,
__lin_interpn__.cc, __luinc__.cc, __magick_read__.cc,
__pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc,
bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
cdisplay.c, cdisplay.h, cellfun.cc, coct-hdf5-types.c, colloc.cc,
comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc,
debug.cc, defaults.cc, defaults.in.h, defun.cc, det.cc, dirfns.cc,
display.cc, dlmread.cc, dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc,
error.cc, errwarn.cc, event-queue.cc, fft.cc, fft2.cc, fftn.cc,
file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, gammainc.cc,
gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc,
gl-render.cc, gl2ps-print.cc, graphics.cc, gripes.cc, hash.cc,
help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jit-ir.cc, jit-ir.h,
jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, kron.cc,
load-path.cc, load-save.cc, lookup.cc, ls-ascii-helper.cc,
ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc,
ls-oct-binary.cc, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc,
lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mex.h,
mexproto.h, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc,
oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-iostrm.cc,
oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc,
oct-stdstrm.h, oct-stream.cc, oct-strstrm.cc, oct-tex-lexer.in.ll,
oct-tex-parser.in.yy, octave-link.cc, ordschur.cc, pager.cc,
pinv.cc, pr-output.cc, procstream.cc, profiler.cc, psi.cc,
pt-jit.cc, pt-jit.h, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc,
regexp.cc, schur.cc, sighandlers.cc, sighandlers.h, siglist.c,
siglist.h, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, spparms.cc,
sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc,
sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, text-renderer.cc,
time.cc, toplev.cc, tril.cc, tsearch.cc, txt-eng.cc, typecast.cc,
urlwrite.cc, utils.cc, variables.cc, xdiv.cc, xgl2ps.c, xnorm.cc,
xpow.cc, zfstream.cc, zfstream.h, __delaunayn__.cc, __eigs__.cc,
__fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc,
audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc,
convhulln.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc,
liboctinterp-build-info.in.cc, mkbuiltins, mkops, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc,
ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc,
ov-complex.cc, ov-cs-list.cc, ov-cx-diag.cc, ov-cx-mat.cc,
ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc,
ov-fcn.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc,
ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc,
ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc,
ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc,
ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc,
ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc,
ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ovl.cc, octave.cc, octave.h,
op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc,
op-bm-sbm.cc, op-cdm-cdm.cc, op-cdm-cm.cc, op-cdm-dm.cc,
op-cdm-m.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cdm.cc,
op-cm-cm.cc, op-cm-cs.cc, op-cm-dm.cc, op-cm-m.cc, op-cm-s.cc,
op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc,
op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-cdm.cc, op-dm-cm.cc,
op-dm-dm.cc, op-dm-m.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-double-conv.cc,
op-fcdm-fcdm.cc, op-fcdm-fcm.cc, op-fcdm-fdm.cc, op-fcdm-fm.cc,
op-fcm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fdm.cc,
op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc,
op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fcdm.cc, op-fdm-fcm.cc,
op-fdm-fdm.cc, op-fdm-fm.cc, op-float-conv.cc, op-fm-fcdm.cc,
op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fdm.cc, op-fm-fm.cc, op-fm-fs.cc,
op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc,
op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc,
op-int-conv.cc, op-m-cdm.cc, op-m-cm.cc, op-m-cs.cc, op-m-dm.cc,
op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc,
op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc,
op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc,
op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc,
op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc,
op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc,
op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc,
op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc,
lex.ll, oct-parse.in.yy, pt-arg-list.cc, pt-array-list.cc,
pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc,
pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc, pt-const.cc,
pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc,
pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc,
pt-loop.h, pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc,
pt-stmt.cc, pt-unop.cc, pt.cc, token.cc, Array-jit.cc, Array-tc.cc,
version.cc, Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc,
Array-f.cc, Array-fC.cc, Array-i.cc, Array-idx-vec.cc, Array-s.cc,
Array-str.cc, Array-util.cc, Array-voidp.cc, Array.cc,
CColVector.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc,
CRowVector.cc, CSparse.cc, MArray-C.cc, MArray-d.cc, MArray-f.cc,
MArray-fC.cc, MArray-i.cc, MArray-s.cc, MSparse-C.cc, MSparse-d.cc,
MatrixType.cc, PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc,
Sparse-d.cc, boolMatrix.cc, boolNDArray.cc, boolSparse.cc,
chMatrix.cc, chNDArray.cc, dColVector.cc, dDiagMatrix.cc,
dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dim-vector.cc,
dim-vector.h, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc,
fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc,
fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc,
int16NDArray.cc, int32NDArray.cc, int64NDArray.cc, int8NDArray.cc,
uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc,
uint8NDArray.cc, Faddeeva.cc, blaswrap.c, cquit.c, f77-extern.cc,
f77-fcn.c, f77-fcn.h, lo-error.c, lo-error.h, quit.cc, quit.h,
liboctave-build-info.in.cc, CollocWt.cc, DASPK.cc, DASRT.cc,
DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, aepbalance.cc,
chol.cc, eigs-base.cc, fEIG.cc, gepbalance.cc, hess.cc,
lo-mappers.cc, lo-specfun.cc, lu.cc, oct-convn.cc, oct-fftw.cc,
oct-norm.cc, oct-rand.cc, oct-spparms.cc, qr.cc, qrp.cc,
randmtzig.cc, randpoisson.cc, schur.cc, sparse-chol.cc,
sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, svd.cc, mk-ops.awk,
mx-defs.h, dir-ops.cc, file-ops.cc, file-stat.cc, lo-sysdep.cc,
mach-info.cc, oct-env.cc, oct-group.cc, oct-passwd.cc,
oct-syscalls.cc, oct-time.cc, oct-uname.cc, pathlen.h, syswait.h,
cmd-edit.cc, cmd-hist.cc, data-conv.cc, f2c-main.c, glob-match.cc,
kpse.cc, lo-array-errwarn.cc, lo-array-gripes.cc, lo-cutils.c,
lo-cutils.h, lo-ieee.cc, lo-ieee.h, lo-regexp.cc, lo-utils.cc,
oct-base64.cc, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h,
oct-locbuf.cc, oct-mutex.cc, oct-rl-edit.c, oct-rl-edit.h,
oct-rl-hist.c, oct-rl-hist.h, oct-shlib.cc, oct-sort.cc,
pathsearch.cc, singleton-cleanup.cc, sparse-sort.cc, sparse-util.cc,
statdefs.h, str-vec.cc, unwind-prot.cc, url-transfer.cc,
acinclude.m4, display-available.c, display-available.h, main-cli.cc,
main-gui.cc, main.in.cc, mkoctfile.in.cc, octave-build-info.in.cc,
octave-config.in.cc, shared-fcns.h:
Use "#if ..." consistently instead of "#ifdef" and "#ifndef".
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 17 May 2016 12:09:30 -0400 |
parents | 5b9868c2e212 |
children | c4ab2e54f100 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19625
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
1 | 25 #endif |
26 | |
1346 | 27 #include <cfloat> |
2825 | 28 #include <cstdio> |
1346 | 29 #include <cstring> |
1343 | 30 |
3503 | 31 #include <iomanip> |
32 #include <iostream> | |
5765 | 33 #include <sstream> |
1728 | 34 #include <string> |
35 | |
4655 | 36 #include "Array-util.h" |
453 | 37 #include "CMatrix.h" |
1 | 38 #include "Range.h" |
2926 | 39 #include "cmd-edit.h" |
1352 | 40 #include "dMatrix.h" |
2891 | 41 #include "lo-mappers.h" |
7231 | 42 #include "lo-math.h" |
2317 | 43 #include "mach-info.h" |
1651 | 44 #include "oct-cmplx.h" |
4153 | 45 #include "quit.h" |
1755 | 46 #include "str-vec.h" |
1 | 47 |
3933 | 48 #include "Cell.h" |
1352 | 49 #include "defun.h" |
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 | 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 | 55 #include "pager.h" |
56 #include "pr-output.h" | |
1282 | 57 #include "sysdep.h" |
6803 | 58 #include "unwind-prot.h" |
1 | 59 #include "utils.h" |
1352 | 60 #include "variables.h" |
1 | 61 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
62 // TRUE means use a scaled fixed point format for 'format long' and |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
63 // 'format short'. |
5794 | 64 static bool Vfixed_point_format = false; |
3105 | 65 |
2165 | 66 // The maximum field width for a number printed by the default output |
67 // routines. | |
5794 | 68 static int Voutput_max_field_width = 10; |
2165 | 69 |
70 // The precision of the numbers printed by the default output | |
71 // routines. | |
5794 | 72 static int Voutput_precision = 5; |
2165 | 73 |
5360 | 74 // TRUE means that the dimensions of empty objects should be printed |
2165 | 75 // like this: x = [](2x0). |
5794 | 76 bool Vprint_empty_dimensions = true; |
2165 | 77 |
78 // TRUE means that the rows of big matrices should be split into | |
79 // smaller slices that fit on the screen. | |
5794 | 80 static bool Vsplit_long_rows = true; |
2165 | 81 |
3018 | 82 // TRUE means don't do any fancy formatting. |
2387 | 83 static bool free_format = false; |
1 | 84 |
3018 | 85 // TRUE means print plus sign for nonzero, blank for zero. |
2387 | 86 static bool plus_format = false; |
1 | 87 |
4632 | 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 | 90 |
6788 | 91 // TRUE means always print in a rational approximation |
92 static bool rat_format = false; | |
93 | |
94 // Used to force the length of the rational approximation string for Frats | |
95 static int rat_string_len = -1; | |
96 | |
3018 | 97 // TRUE means always print like dollars and cents. |
2387 | 98 static bool bank_format = false; |
1282 | 99 |
3018 | 100 // TRUE means print data in hexadecimal format. |
3608 | 101 static int hex_format = 0; |
1282 | 102 |
3018 | 103 // TRUE means print data in binary-bit-pattern format. |
1309 | 104 static int bit_format = 0; |
105 | |
3018 | 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 | 108 |
3018 | 109 // TRUE means use an e format. |
2387 | 110 static bool print_e = false; |
1 | 111 |
4509 | 112 // TRUE means use a g format. |
113 static bool print_g = false; | |
114 | |
3018 | 115 // TRUE means print E instead of e for exponent field. |
2387 | 116 static bool print_big_e = false; |
1 | 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 | 122 class pr_formatted_float; |
6788 | 123 class pr_rational_float; |
3608 | 124 |
4509 | 125 static int |
126 current_output_max_field_width (void) | |
127 { | |
128 return Voutput_max_field_width; | |
129 } | |
130 | |
131 static int | |
132 current_output_precision (void) | |
133 { | |
134 return Voutput_precision; | |
135 } | |
136 | |
3608 | 137 class |
138 float_format | |
139 { | |
140 public: | |
141 | |
4509 | 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 | 148 |
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 | 152 |
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 | 167 |
168 ~float_format (void) { } | |
169 | |
170 float_format& scientific (void) { fmt = std::ios::scientific; return *this; } | |
171 float_format& fixed (void) { fmt = std::ios::fixed; return *this; } | |
172 float_format& general (void) { fmt = 0; return *this; } | |
173 | |
174 float_format& uppercase (void) { up = std::ios::uppercase; return *this; } | |
175 float_format& lowercase (void) { up = 0; return *this; } | |
176 | |
177 float_format& precision (int p) { prec = p; return *this; } | |
178 | |
179 float_format& width (int w) { fw = w; return *this; } | |
180 | |
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 | 183 |
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 | 189 |
6788 | 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 | 192 |
3608 | 193 private: |
194 | |
195 // Field width. Zero means as wide as necessary. | |
196 int fw; | |
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 | 201 // Precision. |
202 int prec; | |
203 | |
204 // Format. | |
205 int fmt; | |
206 | |
207 // E or e. | |
208 int up; | |
209 | |
210 // Show trailing zeros. | |
211 int sp; | |
212 }; | |
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 | 221 |
222 // The expression above is equivalent to x - (x % 3). | |
223 | |
224 // According to the ISO specification for C++ the modulo operator is | |
225 // compiler dependent if any of the arguments are negative. Since | |
226 // this function will need to work on negative arguments, and we want | |
227 // to avoid portability issues, we re-implement the modulo function to | |
228 // the desired behavior (truncation). There may be a gnulib | |
229 // replacement. | |
230 | |
231 // ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO, | |
232 // IEC. 2003 . "the binary % operator yields the remainder from the | |
233 // division of the first expression by the second. .... If both | |
234 // operands are nonnegative then the remainder is nonnegative; if not, | |
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); |
11450
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
245 int logabsval = static_cast<int> (gnulib::floor (log10 (absval))); |
20946 | 246 // Avoid using modulo function with negative arguments for |
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) |
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
261 : static_cast<int> (gnulib::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 | 317 class |
318 pr_formatted_float | |
319 { | |
320 public: | |
321 | |
322 const float_format& f; | |
323 | |
324 double val; | |
325 | |
326 pr_formatted_float (const float_format& f_arg, double val_arg) | |
327 : f (f_arg), val (val_arg) { } | |
328 }; | |
329 | |
330 std::ostream& | |
331 operator << (std::ostream& os, const pr_formatted_float& pff) | |
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 | 335 if (pff.f.fw >= 0) |
3608 | 336 os << std::setw (pff.f.fw); |
337 | |
3682 | 338 if (pff.f.prec >= 0) |
3608 | 339 os << std::setprecision (pff.f.prec); |
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 | 343 |
344 os << pff.val; | |
345 | |
346 return os; | |
347 } | |
348 | |
6788 | 349 static inline std::string |
350 rational_approx (double val, int len) | |
351 { | |
352 std::string s; | |
353 | |
354 if (len <= 0) | |
355 len = 10; | |
356 | |
357 if (xisinf (val)) | |
358 s = "1/0"; | |
359 else if (xisnan (val)) | |
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 () |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
363 || D_NINT (val) == val) |
6788 | 364 { |
365 std::ostringstream buf; | |
366 buf.flags (std::ios::fixed); | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
367 buf << std::setprecision (0) << xround (val); |
6788 | 368 s = buf.str (); |
369 } | |
370 else | |
371 { | |
372 double lastn = 1.; | |
373 double lastd = 0.; | |
374 double n = xround (val); | |
375 double d = 1.; | |
376 double frac = val - n; | |
377 int m = 0; | |
378 | |
379 std::ostringstream buf2; | |
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 | 383 |
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; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
387 double step = xround (flip); |
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 ? |
19363
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
392 if (fabs (frac) < 1 / 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 |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
420 if (fabs (n) > std::numeric_limits<int>::max () |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
421 || fabs (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 | 426 |
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 | 438 } |
439 | |
440 return s; | |
441 } | |
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 | 457 class |
458 pr_rational_float | |
459 { | |
460 public: | |
461 | |
462 const float_format& f; | |
463 | |
464 double val; | |
465 | |
466 pr_rational_float (const float_format& f_arg, double val_arg) | |
467 : f (f_arg), val (val_arg) { } | |
468 }; | |
469 | |
470 std::ostream& | |
471 operator << (std::ostream& os, const pr_rational_float& prf) | |
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 | 475 int fw = (rat_string_len > 0 ? rat_string_len : prf.f.fw); |
476 std::string s = rational_approx (prf.val, fw); | |
477 | |
478 if (fw >= 0) | |
479 os << std::setw (fw); | |
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 | 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 | 485 os << "*"; |
486 else | |
487 os << s; | |
488 | |
489 return os; | |
490 } | |
491 | |
3608 | 492 // Current format for real numbers and the real part of complex |
493 // numbers. | |
494 static float_format *curr_real_fmt = 0; | |
495 | |
496 // Current format for the imaginary part of complex numbers. | |
497 static float_format *curr_imag_fmt = 0; | |
1309 | 498 |
1 | 499 static double |
164 | 500 pr_max_internal (const Matrix& m) |
1 | 501 { |
5275 | 502 octave_idx_type nr = m.rows (); |
503 octave_idx_type nc = m.columns (); | |
1 | 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 | 506 |
5748 | 507 bool all_inf_or_nan = true; |
508 | |
5275 | 509 for (octave_idx_type j = 0; j < nc; j++) |
510 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 511 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
512 double val = m(i,j); |
16971
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
513 if (! xfinite (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 | 520 } |
3608 | 521 |
5748 | 522 if (all_inf_or_nan) |
523 result = 0.0; | |
524 | |
1 | 525 return result; |
526 } | |
527 | |
528 static double | |
164 | 529 pr_min_internal (const Matrix& m) |
1 | 530 { |
5275 | 531 octave_idx_type nr = m.rows (); |
532 octave_idx_type nc = m.columns (); | |
1 | 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 | 535 |
5748 | 536 bool all_inf_or_nan = true; |
537 | |
5275 | 538 for (octave_idx_type j = 0; j < nc; j++) |
539 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 540 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
541 double val = m(i,j); |
17871
5ac0545fb4c0
fix printing of matrix values (bug #40470)
John W. Eaton <jwe@octave.org>
parents:
17867
diff
changeset
|
542 if (! xfinite (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 | 549 } |
3608 | 550 |
5748 | 551 if (all_inf_or_nan) |
552 result = 0.0; | |
553 | |
1 | 554 return result; |
555 } | |
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 | 558 |
1 | 559 static void |
6959 | 560 set_real_format (int digits, bool inf_or_nan, bool int_only, int &fw) |
1 | 561 { |
3608 | 562 static float_format fmt; |
1 | 563 |
2165 | 564 int prec = Voutput_precision; |
1 | 565 |
566 int ld, rd; | |
567 | |
6788 | 568 if (rat_format) |
569 { | |
570 fw = 0; | |
571 rd = 0; | |
572 } | |
573 else if (bank_format) | |
1 | 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 | 578 rd = 2; |
579 } | |
1282 | 580 else if (hex_format) |
581 { | |
582 fw = 2 * sizeof (double); | |
583 rd = 0; | |
584 } | |
1309 | 585 else if (bit_format) |
586 { | |
587 fw = 8 * sizeof (double); | |
588 rd = 0; | |
589 } | |
3611 | 590 else if (inf_or_nan || int_only) |
1 | 591 { |
5832 | 592 fw = 1 + digits; |
5748 | 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 | 595 rd = fw; |
1 | 596 } |
597 else | |
598 { | |
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 | 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 | 609 |
5832 | 610 fw = 1 + ld + 1 + rd; |
5748 | 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 | 613 } |
614 | |
6788 | 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 | 617 { |
4509 | 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 | 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 | 642 |
1 | 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 | 645 } |
5086 | 646 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 647 fmt = float_format (fw, rd); |
1 | 648 else |
3608 | 649 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 650 |
3608 | 651 curr_real_fmt = &fmt; |
1 | 652 } |
653 | |
1658 | 654 static void |
655 set_format (double d, int& fw) | |
656 { | |
657 curr_real_fmt = 0; | |
658 curr_imag_fmt = 0; | |
659 | |
660 if (free_format) | |
661 return; | |
662 | |
5389 | 663 bool inf_or_nan = (xisinf (d) || xisnan (d)); |
1658 | 664 |
3611 | 665 bool int_only = (! inf_or_nan && D_NINT (d) == d); |
1658 | 666 |
667 double d_abs = d < 0.0 ? -d : d; | |
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 | 670 |
6959 | 671 set_real_format (digits, inf_or_nan, int_only, fw); |
1658 | 672 } |
673 | |
1 | 674 static inline void |
675 set_format (double d) | |
676 { | |
677 int fw; | |
678 set_format (d, fw); | |
679 } | |
680 | |
681 static void | |
6959 | 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 | 684 { |
3608 | 685 static float_format fmt; |
1 | 686 |
2165 | 687 int prec = Voutput_precision; |
1 | 688 |
689 int ld, rd; | |
690 | |
6788 | 691 if (rat_format) |
692 { | |
693 fw = 9; | |
694 rd = 0; | |
695 } | |
696 else if (bank_format) | |
1 | 697 { |
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 | 702 rd = 2; |
703 } | |
1282 | 704 else if (hex_format) |
705 { | |
706 fw = 2 * sizeof (double); | |
707 rd = 0; | |
708 } | |
1309 | 709 else if (bit_format) |
710 { | |
711 fw = 8 * sizeof (double); | |
712 rd = 0; | |
713 } | |
4509 | 714 else if (Vfixed_point_format && ! print_g) |
3268 | 715 { |
716 rd = prec; | |
717 fw = rd + 2; | |
5748 | 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 | 720 } |
1715 | 721 else if (int_or_inf_or_nan) |
1 | 722 { |
723 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 724 fw = digits <= 0 ? 2 : digits + 1; |
5748 | 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 | 727 rd = fw; |
1 | 728 } |
729 else | |
730 { | |
731 int ld_max, rd_max; | |
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 | 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 | 744 |
745 int ld_min, rd_min; | |
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 | 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 | 758 |
759 ld = ld_max > ld_min ? ld_max : ld_min; | |
760 rd = rd_max > rd_min ? rd_max : rd_min; | |
761 | |
5832 | 762 fw = 1 + ld + 1 + rd; |
5748 | 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 | 765 } |
766 | |
6788 | 767 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 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 | 771 { |
4509 | 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 | 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 | 795 |
1 | 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 | 798 } |
5086 | 799 else if (! bank_format && int_or_inf_or_nan) |
3611 | 800 fmt = float_format (fw, rd); |
1 | 801 else |
3608 | 802 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 803 |
3608 | 804 curr_real_fmt = &fmt; |
1 | 805 } |
806 | |
1658 | 807 static void |
3105 | 808 set_format (const Matrix& m, int& fw, double& scale) |
1658 | 809 { |
810 curr_real_fmt = 0; | |
811 curr_imag_fmt = 0; | |
812 | |
813 if (free_format) | |
814 return; | |
815 | |
2387 | 816 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658 | 817 |
2387 | 818 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658 | 819 |
2387 | 820 Matrix m_abs = m.abs (); |
1658 | 821 double max_abs = pr_max_internal (m_abs); |
822 double min_abs = pr_min_internal (m_abs); | |
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 | 830 |
6959 | 831 set_real_matrix_format (x_max, x_min, inf_or_nan, int_or_inf_or_nan, fw); |
1658 | 832 } |
833 | |
1 | 834 static inline void |
164 | 835 set_format (const Matrix& m) |
1 | 836 { |
837 int fw; | |
3105 | 838 double scale; |
839 set_format (m, fw, scale); | |
1 | 840 } |
841 | |
842 static void | |
6959 | 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 | 845 { |
3608 | 846 static float_format r_fmt; |
847 static float_format i_fmt; | |
1 | 848 |
2165 | 849 int prec = Voutput_precision; |
1 | 850 |
851 int ld, rd; | |
852 | |
6788 | 853 if (rat_format) |
854 { | |
855 i_fw = 0; | |
856 r_fw = 0; | |
857 rd = 0; | |
858 } | |
859 else if (bank_format) | |
1 | 860 { |
861 int digits = r_x; | |
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 | 866 rd = 2; |
867 } | |
1282 | 868 else if (hex_format) |
869 { | |
870 r_fw = 2 * sizeof (double); | |
871 i_fw = 2 * sizeof (double); | |
872 rd = 0; | |
873 } | |
1309 | 874 else if (bit_format) |
875 { | |
876 r_fw = 8 * sizeof (double); | |
877 i_fw = 8 * sizeof (double); | |
878 rd = 0; | |
879 } | |
1658 | 880 else if (inf_or_nan || int_only) |
1 | 881 { |
882 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 883 i_fw = digits <= 0 ? 1 : digits; |
884 r_fw = i_fw + 1; | |
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 | 890 rd = r_fw; |
1 | 891 } |
892 else | |
893 { | |
894 int ld_max, rd_max; | |
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 | 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 | 907 |
908 int ld_min, rd_min; | |
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 | 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 | 921 |
922 ld = ld_max > ld_min ? ld_max : ld_min; | |
923 rd = rd_max > rd_min ? rd_max : rd_min; | |
924 | |
5945 | 925 i_fw = ld + 1 + rd; |
926 r_fw = i_fw + 1; | |
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 | 932 } |
933 | |
6788 | 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 | 936 { |
4509 | 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 | 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 | 973 |
1 | 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 | 979 } |
5086 | 980 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 981 { |
982 r_fmt = float_format (r_fw, rd); | |
983 i_fmt = float_format (i_fw, rd); | |
984 } | |
1 | 985 else |
986 { | |
3608 | 987 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
988 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 989 } |
990 | |
3608 | 991 curr_real_fmt = &r_fmt; |
992 curr_imag_fmt = &i_fmt; | |
1 | 993 } |
994 | |
1658 | 995 static void |
996 set_format (const Complex& c, int& r_fw, int& i_fw) | |
997 { | |
998 curr_real_fmt = 0; | |
999 curr_imag_fmt = 0; | |
1000 | |
1001 if (free_format) | |
1002 return; | |
1003 | |
1004 double rp = c.real (); | |
1005 double ip = c.imag (); | |
1006 | |
2387 | 1007 bool inf_or_nan = (xisinf (c) || xisnan (c)); |
1658 | 1008 |
2387 | 1009 bool int_only = (D_NINT (rp) == rp && D_NINT (ip) == ip); |
1658 | 1010 |
1011 double r_abs = rp < 0.0 ? -rp : rp; | |
1012 double i_abs = ip < 0.0 ? -ip : ip; | |
1013 | |
16971
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
1014 int r_x = (! xfinite (rp) || r_abs == 0.0) ? 0 : num_digits (r_abs); |
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
1015 |
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
1016 int i_x = (! xfinite (ip) || i_abs == 0.0) ? 0 : num_digits (i_abs); |
1658 | 1017 |
1018 int x_max, x_min; | |
1019 | |
1020 if (r_x > i_x) | |
1021 { | |
1022 x_max = r_x; | |
1023 x_min = i_x; | |
1024 } | |
1025 else | |
1026 { | |
1027 x_max = i_x; | |
1028 x_min = r_x; | |
1029 } | |
1030 | |
6959 | 1031 set_complex_format (x_max, x_min, r_x, inf_or_nan, int_only, r_fw, i_fw); |
1658 | 1032 } |
1033 | |
1 | 1034 static inline void |
164 | 1035 set_format (const Complex& c) |
1 | 1036 { |
1037 int r_fw, i_fw; | |
1038 set_format (c, r_fw, i_fw); | |
1039 } | |
1040 | |
1041 static void | |
6959 | 1042 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
|
1043 int r_x_min, bool inf_or_nan, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1044 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
1 | 1045 { |
3608 | 1046 static float_format r_fmt; |
1047 static float_format i_fmt; | |
1 | 1048 |
2165 | 1049 int prec = Voutput_precision; |
1 | 1050 |
1051 int ld, rd; | |
1052 | |
6788 | 1053 if (rat_format) |
1054 { | |
1055 i_fw = 9; | |
1056 r_fw = 9; | |
1057 rd = 0; | |
1058 } | |
1059 else if (bank_format) | |
1 | 1060 { |
1061 int digits = r_x_max > r_x_min ? r_x_max : r_x_min; | |
1062 i_fw = 0; | |
17847
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
1063 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
|
1064 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
|
1065 r_fw = 5; |
1 | 1066 rd = 2; |
1067 } | |
1282 | 1068 else if (hex_format) |
1069 { | |
1070 r_fw = 2 * sizeof (double); | |
1071 i_fw = 2 * sizeof (double); | |
1072 rd = 0; | |
1073 } | |
1309 | 1074 else if (bit_format) |
1075 { | |
1076 r_fw = 8 * sizeof (double); | |
1077 i_fw = 8 * sizeof (double); | |
1078 rd = 0; | |
1079 } | |
4509 | 1080 else if (Vfixed_point_format && ! print_g) |
3268 | 1081 { |
1082 rd = prec; | |
5945 | 1083 i_fw = rd + 1; |
1084 r_fw = i_fw + 1; | |
1085 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1086 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1087 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1088 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1089 } |
3268 | 1090 } |
1715 | 1091 else if (int_or_inf_or_nan) |
1 | 1092 { |
1093 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 1094 i_fw = digits <= 0 ? 1 : digits; |
1095 r_fw = i_fw + 1; | |
1096 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1097 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1098 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1099 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1100 } |
3682 | 1101 rd = r_fw; |
1 | 1102 } |
1103 else | |
1104 { | |
1105 int ld_max, rd_max; | |
1106 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1107 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1108 ld_max = x_max; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1109 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
|
1110 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1111 } |
1 | 1112 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1113 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1114 ld_max = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1115 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
|
1116 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1117 } |
1 | 1118 |
1119 int ld_min, rd_min; | |
1120 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1121 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1122 ld_min = x_min; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1123 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
|
1124 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1125 } |
1 | 1126 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1127 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1128 ld_min = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1129 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
|
1130 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1131 } |
1 | 1132 |
1133 ld = ld_max > ld_min ? ld_max : ld_min; | |
1134 rd = rd_max > rd_min ? rd_max : rd_min; | |
1135 | |
5945 | 1136 i_fw = ld + 1 + rd; |
1137 r_fw = i_fw + 1; | |
1138 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1139 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1140 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1141 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1142 } |
1 | 1143 } |
1144 | |
6788 | 1145 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 1146 && (print_e |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1147 || print_eng || print_g |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1148 || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) |
1 | 1149 { |
4509 | 1150 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1151 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1152 r_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1153 i_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1154 } |
4509 | 1155 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1156 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1157 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1158 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
|
1159 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1160 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1161 if (print_eng) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1162 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1163 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
|
1164 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
|
1165 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
|
1166 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1167 i_fw = 5; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1168 r_fw = 6; |
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 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
|
1171 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
|
1172 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1173 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1174 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1175 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
|
1176 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
|
1177 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
|
1178 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1179 i_fw = 3; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1180 r_fw = 4; |
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 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
|
1183 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
|
1184 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1185 } |
3608 | 1186 |
1 | 1187 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1188 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1189 r_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1190 i_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1191 } |
1 | 1192 } |
5086 | 1193 else if (! bank_format && int_or_inf_or_nan) |
3611 | 1194 { |
1195 r_fmt = float_format (r_fw, rd); | |
1196 i_fmt = float_format (i_fw, rd); | |
1197 } | |
1 | 1198 else |
1199 { | |
3608 | 1200 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
1201 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 1202 } |
1203 | |
3608 | 1204 curr_real_fmt = &r_fmt; |
1205 curr_imag_fmt = &i_fmt; | |
1 | 1206 } |
1207 | |
1658 | 1208 static void |
3105 | 1209 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
1658 | 1210 { |
1211 curr_real_fmt = 0; | |
1212 curr_imag_fmt = 0; | |
1213 | |
1214 if (free_format) | |
1215 return; | |
1216 | |
1217 Matrix rp = real (cm); | |
1218 Matrix ip = imag (cm); | |
1219 | |
2387 | 1220 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658 | 1221 |
2387 | 1222 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
|
1223 && ip.all_elements_are_int_or_inf_or_nan ()); |
1658 | 1224 |
2387 | 1225 Matrix r_m_abs = rp.abs (); |
1658 | 1226 double r_max_abs = pr_max_internal (r_m_abs); |
1227 double r_min_abs = pr_min_internal (r_m_abs); | |
1228 | |
2387 | 1229 Matrix i_m_abs = ip.abs (); |
1658 | 1230 double i_max_abs = pr_max_internal (i_m_abs); |
1231 double i_min_abs = pr_min_internal (i_m_abs); | |
1232 | |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1233 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
|
1234 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1235 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
|
1236 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1237 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
|
1238 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1239 int i_x_min = i_min_abs == 0.0 ? 0 : num_digits (i_min_abs); |
1658 | 1240 |
1241 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max; | |
1242 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min; | |
1243 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1244 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
|
1245 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1)); |
3105 | 1246 |
6959 | 1247 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
|
1248 int_or_inf_or_nan, r_fw, i_fw); |
1658 | 1249 } |
1250 | |
1 | 1251 static inline void |
164 | 1252 set_format (const ComplexMatrix& cm) |
1 | 1253 { |
1254 int r_fw, i_fw; | |
3105 | 1255 double scale; |
1256 set_format (cm, r_fw, i_fw, scale); | |
1 | 1257 } |
1258 | |
1259 static void | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1260 set_range_format (int x_max, int x_min, int all_ints, int& fw) |
1 | 1261 { |
3608 | 1262 static float_format fmt; |
1 | 1263 |
2165 | 1264 int prec = Voutput_precision; |
1 | 1265 |
1266 int ld, rd; | |
1267 | |
6788 | 1268 if (rat_format) |
1269 { | |
1270 fw = 9; | |
1271 rd = 0; | |
1272 } | |
1273 else if (bank_format) | |
1 | 1274 { |
1275 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
|
1276 fw = digits < 0 ? 5 : digits + 4; |
1 | 1277 rd = 2; |
1278 } | |
1282 | 1279 else if (hex_format) |
1280 { | |
1281 fw = 2 * sizeof (double); | |
1282 rd = 0; | |
1283 } | |
1309 | 1284 else if (bit_format) |
1285 { | |
1286 fw = 8 * sizeof (double); | |
1287 rd = 0; | |
1288 } | |
1658 | 1289 else if (all_ints) |
1 | 1290 { |
1291 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
|
1292 fw = digits + 1; |
3682 | 1293 rd = fw; |
1 | 1294 } |
4509 | 1295 else if (Vfixed_point_format && ! print_g) |
3105 | 1296 { |
1297 rd = prec; | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1298 fw = rd + 3; |
3105 | 1299 } |
1 | 1300 else |
1301 { | |
1302 int ld_max, rd_max; | |
1303 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1304 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1305 ld_max = x_max; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1306 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
|
1307 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1308 } |
1 | 1309 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1310 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1311 ld_max = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1312 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
|
1313 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1314 } |
1 | 1315 |
1316 int ld_min, rd_min; | |
1317 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1318 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1319 ld_min = x_min; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1320 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
|
1321 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1322 } |
1 | 1323 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1324 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1325 ld_min = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1326 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
|
1327 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1328 } |
1 | 1329 |
1330 ld = ld_max > ld_min ? ld_max : ld_min; | |
1331 rd = rd_max > rd_min ? rd_max : rd_min; | |
1332 | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1333 fw = ld + rd + 3; |
1 | 1334 } |
1335 | |
6788 | 1336 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 1337 && (print_e |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1338 || print_eng || print_g |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1339 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1 | 1340 { |
4509 | 1341 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1342 fmt = float_format (); |
4509 | 1343 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1344 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1345 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1346 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
|
1347 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1348 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1349 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1350 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1351 fw = 5 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1352 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
|
1353 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1354 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1355 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1356 fw = 3 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1357 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
|
1358 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1359 } |
3608 | 1360 |
1 | 1361 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1362 fmt.uppercase (); |
1 | 1363 } |
5086 | 1364 else if (! bank_format && all_ints) |
3611 | 1365 fmt = float_format (fw, rd); |
1 | 1366 else |
3608 | 1367 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 1368 |
3608 | 1369 curr_real_fmt = &fmt; |
1 | 1370 } |
1371 | |
1658 | 1372 static void |
3105 | 1373 set_format (const Range& r, int& fw, double& scale) |
1658 | 1374 { |
1375 curr_real_fmt = 0; | |
1376 curr_imag_fmt = 0; | |
1377 | |
1378 if (free_format) | |
1379 return; | |
1380 | |
1381 double r_min = r.base (); | |
1382 double r_max = r.limit (); | |
1383 | |
1384 if (r_max < r_min) | |
1385 { | |
1386 double tmp = r_max; | |
1387 r_max = r_min; | |
1388 r_min = tmp; | |
1389 } | |
1390 | |
2387 | 1391 bool all_ints = r.all_elements_are_ints (); |
1658 | 1392 |
1393 double max_abs = r_max < 0.0 ? -r_max : r_max; | |
1394 double min_abs = r_min < 0.0 ? -r_min : r_min; | |
1395 | |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1396 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
|
1397 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1398 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
|
1399 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1400 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
|
1401 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1)); |
3105 | 1402 |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1403 set_range_format (x_max, x_min, all_ints, fw); |
1658 | 1404 } |
1405 | |
1 | 1406 static inline void |
164 | 1407 set_format (const Range& r) |
1 | 1408 { |
1409 int fw; | |
3105 | 1410 double scale; |
1411 set_format (r, fw, scale); | |
1 | 1412 } |
1413 | |
1282 | 1414 union equiv |
1415 { | |
1416 double d; | |
1417 unsigned char i[sizeof (double)]; | |
1418 }; | |
1419 | |
1309 | 1420 #define PRINT_CHAR_BITS(os, c) \ |
1421 do \ | |
1422 { \ | |
1423 unsigned char ctmp = c; \ | |
1424 char stmp[9]; \ | |
1488 | 1425 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
1426 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ | |
1427 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ | |
1428 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ | |
1429 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ | |
1430 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ | |
1431 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ | |
1432 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ | |
1309 | 1433 stmp[8] = '\0'; \ |
3013 | 1434 os << stmp; \ |
1309 | 1435 } \ |
1436 while (0) | |
1437 | |
1438 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ | |
1439 do \ | |
1440 { \ | |
1441 unsigned char ctmp = c; \ | |
1442 char stmp[9]; \ | |
1488 | 1443 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
1444 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ | |
1445 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ | |
1446 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ | |
1447 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ | |
1448 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ | |
1449 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ | |
1450 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ | |
1309 | 1451 stmp[8] = '\0'; \ |
3013 | 1452 os << stmp; \ |
1309 | 1453 } \ |
1454 while (0) | |
1455 | |
2522 | 1456 static void |
3608 | 1457 pr_any_float (const float_format *fmt, std::ostream& os, double d, int fw = 0) |
1 | 1458 { |
529 | 1459 if (fmt) |
1 | 1460 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1461 // 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
|
1462 // for hex and bit formats. |
5544 | 1463 // |
1464 // {bit,hex}_format == 1: print big-endian | |
1465 // {bit,hex}_format == 2: print native | |
1466 | |
1282 | 1467 if (hex_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1468 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1469 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
|
1470 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1471 equiv tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1472 tmp.d = d; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1473 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1474 // 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
|
1475 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1476 // 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
|
1477 // interrupted before resetting the format flags and fill |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1478 // character? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1479 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1480 oct_mach_info::float_format flt_fmt = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1481 oct_mach_info::native_float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1482 |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1483 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
|
1484 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
|
1485 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1486 if (hex_format > 1 |
17415
3856298f1ff8
eliminate unimplemented vax and cray floating point formats
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
1487 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian) |
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 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
|
1490 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
|
1491 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1492 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1493 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1494 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
|
1495 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
|
1496 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1497 } |
1309 | 1498 else if (bit_format) |
10315
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 equiv tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1501 tmp.d = d; |
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 oct_mach_info::float_format flt_fmt = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1504 oct_mach_info::native_float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1505 |
17415
3856298f1ff8
eliminate unimplemented vax and cray floating point formats
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
1506 if (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1507 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1508 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
|
1509 PRINT_CHAR_BITS (os, tmp.i[i]); |
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 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1512 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1513 if (bit_format > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1514 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1515 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
|
1516 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); |
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 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1519 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1520 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
|
1521 PRINT_CHAR_BITS (os, tmp.i[i]); |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1524 } |
6788 | 1525 else if (octave_is_NA (d)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1526 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1527 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
|
1528 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1529 if (fw > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1530 os << std::setw (fw) << "NA"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1531 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1532 os << "NA"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1533 } |
6788 | 1534 else if (rat_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1535 os << pr_rational_float (*fmt, d); |
1282 | 1536 else if (xisinf (d)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1537 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1538 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
|
1539 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1540 const char *s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1541 if (d < 0.0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1542 s = "-Inf"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1543 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1544 s = "Inf"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1545 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1546 if (fw > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1547 os << std::setw (fw) << s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1548 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1549 os << s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1550 } |
1 | 1551 else if (xisnan (d)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1552 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1553 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
|
1554 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1555 if (fw > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1556 os << std::setw (fw) << "NaN"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1557 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1558 os << "NaN"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1559 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1560 else if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1561 os << pr_engineering_float (*fmt, d); |
1 | 1562 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1563 os << pr_formatted_float (*fmt, d); |
1 | 1564 } |
529 | 1565 else |
1566 os << d; | |
1 | 1567 } |
1568 | |
1569 static inline void | |
3608 | 1570 pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0) |
1 | 1571 { |
4509 | 1572 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3608 | 1573 d /= scale; |
1574 | |
1 | 1575 pr_any_float (curr_real_fmt, os, d, fw); |
1576 } | |
1577 | |
1578 static inline void | |
3523 | 1579 pr_imag_float (std::ostream& os, double d, int fw = 0) |
1 | 1580 { |
1581 pr_any_float (curr_imag_fmt, os, d, fw); | |
1582 } | |
1583 | |
2522 | 1584 static void |
3608 | 1585 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
|
1586 int i_fw = 0, double scale = 1.0) |
1 | 1587 { |
4509 | 1588 Complex tmp |
1589 = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c; | |
3608 | 1590 |
1591 double r = tmp.real (); | |
1592 | |
1 | 1593 pr_float (os, r, r_fw); |
3608 | 1594 |
1 | 1595 if (! bank_format) |
1596 { | |
3608 | 1597 double i = tmp.imag (); |
4349 | 1598 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
|
1599 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1600 os << " - "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1601 i = -i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1602 pr_imag_float (os, i, i_fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1603 } |
1 | 1604 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1605 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1606 if (hex_format || bit_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1607 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1608 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1609 os << " + "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1610 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1611 pr_imag_float (os, i, i_fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1612 } |
1 | 1613 os << "i"; |
1614 } | |
1615 } | |
1616 | |
626 | 1617 static void |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1618 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
|
1619 bool pr_as_read_syntax) |
626 | 1620 { |
1621 assert (nr == 0 || nc == 0); | |
1622 | |
1623 if (pr_as_read_syntax) | |
1624 { | |
1625 if (nr == 0 && nc == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1626 os << "[]"; |
626 | 1627 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1628 os << "zeros (" << nr << ", " << nc << ")"; |
626 | 1629 } |
1630 else | |
1631 { | |
1632 os << "[]"; | |
4559 | 1633 |
2165 | 1634 if (Vprint_empty_dimensions) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1635 os << "(" << nr << "x" << nc << ")"; |
626 | 1636 } |
1637 } | |
1638 | |
1186 | 1639 static void |
4559 | 1640 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
|
1641 bool pr_as_read_syntax) |
4559 | 1642 { |
1643 assert (dims.any_zero ()); | |
1644 | |
1645 if (pr_as_read_syntax) | |
1646 os << "zeros (" << dims.str (',') << ")"; | |
1647 else | |
1648 { | |
1649 os << "[]"; | |
1650 | |
1651 if (Vprint_empty_dimensions) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1652 os << "(" << dims.str () << ")"; |
4559 | 1653 } |
1654 } | |
1655 | |
1656 static void | |
3523 | 1657 pr_scale_header (std::ostream& os, double scale) |
3105 | 1658 { |
4509 | 1659 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3105 | 1660 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1661 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
|
1662 |
3568 | 1663 os << " " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1664 << std::setw (8) << std::setprecision (1) |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21583
diff
changeset
|
1665 << 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
|
1666 << scale |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1667 << " *\n"; |
3105 | 1668 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1669 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1670 os << "\n"; |
3105 | 1671 } |
1672 } | |
1673 | |
1674 static void | |
5275 | 1675 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
|
1676 octave_idx_type lim, octave_idx_type col, int extra_indent) |
1186 | 1677 { |
2165 | 1678 if (total_width > max_width && Vsplit_long_rows) |
1186 | 1679 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1680 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
|
1681 |
4833 | 1682 if (col != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1683 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1684 if (Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1685 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1686 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1687 os << "\n\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1688 } |
1186 | 1689 |
5275 | 1690 octave_idx_type num_cols = lim - col; |
1186 | 1691 |
3548 | 1692 os << std::setw (extra_indent) << ""; |
1972 | 1693 |
1186 | 1694 if (num_cols == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1695 os << " Column " << col + 1 << ":\n"; |
1186 | 1696 else if (num_cols == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1697 os << " Columns " << col + 1 << " and " << lim << ":\n"; |
1186 | 1698 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1699 os << " Columns " << col + 1 << " through " << lim << ":\n"; |
2915 | 1700 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1701 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1702 os << "\n"; |
1186 | 1703 } |
1704 } | |
1705 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
1706 template <typename T> |
6018 | 1707 /* static */ inline void |
5030 | 1708 pr_plus_format (std::ostream& os, const T& val) |
3248 | 1709 { |
5030 | 1710 if (val > T (0)) |
4632 | 1711 os << plus_format_chars[0]; |
5030 | 1712 else if (val < T (0)) |
4632 | 1713 os << plus_format_chars[1]; |
3248 | 1714 else |
4632 | 1715 os << plus_format_chars[2]; |
3248 | 1716 } |
1717 | |
1 | 1718 void |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1719 octave_print_internal (std::ostream&, char, bool) |
1 | 1720 { |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1721 panic_impossible (); |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1722 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1723 |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1724 void |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1725 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
|
1726 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
|
1727 { |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1728 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
|
1729 os << d; |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1730 else if (plus_format) |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1731 pr_plus_format (os, d); |
1 | 1732 else |
1733 { | |
1734 set_format (d); | |
1735 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1736 os << d; |
1 | 1737 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1738 pr_float (os, d); |
1 | 1739 } |
1740 } | |
1741 | |
1742 void | |
3608 | 1743 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
|
1744 bool pr_as_read_syntax, int extra_indent) |
1 | 1745 { |
5275 | 1746 octave_idx_type nr = m.rows (); |
1747 octave_idx_type nc = m.columns (); | |
1 | 1748 |
2408 | 1749 if (nr == 0 || nc == 0) |
626 | 1750 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1751 else if (plus_format && ! pr_as_read_syntax) | |
1 | 1752 { |
5275 | 1753 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
|
1754 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1755 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
|
1756 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1757 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1758 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1759 pr_plus_format (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1760 } |
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 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1763 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1764 } |
1 | 1765 } |
1766 else | |
1767 { | |
1768 int fw; | |
3105 | 1769 double scale = 1.0; |
1770 set_format (m, fw, scale); | |
1 | 1771 int column_width = fw + 2; |
5275 | 1772 octave_idx_type total_width = nc * column_width; |
1773 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 1774 |
626 | 1775 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1776 max_width -= 4; |
1972 | 1777 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1778 max_width -= extra_indent; |
1972 | 1779 |
1780 if (max_width < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1781 max_width = 0; |
626 | 1782 |
1 | 1783 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1784 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1785 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1786 os << "[\n"; |
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 os << m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1789 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1790 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1791 os << "]"; |
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 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1794 } |
1 | 1795 |
5275 | 1796 octave_idx_type inc = nc; |
2165 | 1797 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
|
1798 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1799 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1800 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1801 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1802 } |
1 | 1803 |
626 | 1804 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1805 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1806 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
|
1807 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1808 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1809 while (col < nc) |
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 lim = col + inc < nc ? col + inc : nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1812 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1813 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
|
1814 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1815 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1816 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1817 if (i == 0 && j == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1818 os << "[ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1819 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1820 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1821 if (j > col && j < lim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1822 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1823 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1824 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1825 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1826 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1827 pr_float (os, m(i,j)); |
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 col += inc; |
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 if (col >= nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1833 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1834 if (i == nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1835 os << " ]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1836 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1837 os << ";\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1838 } |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1843 } |
626 | 1844 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1845 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1846 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
|
1847 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1848 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1849 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1850 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
|
1851 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1852 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
|
1853 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1854 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
|
1855 extra_indent); |
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 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
|
1858 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1859 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1860 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1861 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
|
1862 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1863 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1864 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1865 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1866 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1867 pr_float (os, m(i,j), fw, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1868 } |
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 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1871 os << "\n"; |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1874 } |
1 | 1875 } |
1876 } | |
1877 | |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1878 void |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1879 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
|
1880 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1881 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1882 octave_idx_type nr = m.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1883 octave_idx_type nc = m.columns (); |
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 if (nr == 0 || nc == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1886 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
|
1887 else if (plus_format && ! pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1888 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1889 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
|
1890 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1891 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
|
1892 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1893 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1894 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1895 pr_plus_format (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1896 } |
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 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1899 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1900 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1901 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1902 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1903 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1904 int fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1905 double scale = 1.0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1906 set_format (Matrix (m.diag ()), fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1907 int column_width = fw + 2; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1908 octave_idx_type total_width = nc * column_width; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1909 octave_idx_type max_width = command_editor::terminal_cols (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1910 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1911 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1912 max_width -= 4; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1913 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1914 max_width -= extra_indent; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1915 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1916 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1917 max_width = 0; |
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 (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1920 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1921 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1922 os << "[\n"; |
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 os << Matrix (m); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1925 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1926 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1927 os << "]"; |
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 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1930 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1931 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1932 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1933 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
|
1934 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1935 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1936 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1937 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1938 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1939 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1940 if (pr_as_read_syntax) |
10315
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 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1943 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1944 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1945 while (col < nc) |
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 lim = col + inc < nc ? col + inc : nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1948 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1949 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1950 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
1951 octave_quit (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1952 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1953 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1954 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1955 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1956 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1957 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1958 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1959 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1960 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1961 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1962 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1963 pr_float (os, m(j,j)); |
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 col += inc; |
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 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1969 os << " ]"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1970 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1971 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1972 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1973 os << ")"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1974 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1975 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1976 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1977 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
|
1978 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1979 os << "Diagonal Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1980 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1981 os << "\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1982 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1983 pr_scale_header (os, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1984 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1985 // kluge. Get the true width of a number. |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1986 int zero_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1987 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1988 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1989 std::ostringstream tmp_oss; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1990 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
|
1991 zero_fw = tmp_oss.str ().length (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1992 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1993 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1994 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
|
1995 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1996 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
|
1997 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1998 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
|
1999 extra_indent); |
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 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
|
2002 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2003 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2004 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2005 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
|
2006 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2007 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2008 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2009 os << " "; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2010 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2011 if (i == j) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2012 pr_float (os, m(i,j), fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2013 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2014 os << std::setw (zero_fw) << '0'; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2015 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2016 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2017 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2018 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2019 os << "\n"; |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2022 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2023 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2024 } |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2025 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2026 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
|
2027 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
|
2028 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
|
2029 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2030 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2031 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
|
2032 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
|
2033 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2034 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2035 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2036 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
|
2037 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2038 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
|
2039 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2040 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
|
2041 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2042 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
|
2043 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2044 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
|
2045 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
|
2046 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2047 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
|
2048 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
|
2049 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2050 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
|
2051 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2052 octave_quit (); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2053 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2054 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
|
2055 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2056 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
|
2057 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2058 nm += "(:,:,"; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2059 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2060 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
|
2061 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2062 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
|
2063 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2064 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
|
2065 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2066 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
|
2067 buf << ","; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2068 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2069 buf << ")"; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2070 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2071 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2072 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
|
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 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
|
2076 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2077 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
|
2078 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
|
2079 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2080 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
|
2081 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
|
2082 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2083 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
|
2084 = 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
|
2085 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2086 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
|
2087 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2088 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
|
2089 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2090 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2091 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2092 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
|
2093 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
|
2094 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2095 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2096 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
|
2097 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
|
2098 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2099 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2100 } |
4532 | 2101 |
4513 | 2102 void |
2103 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
|
2104 bool pr_as_read_syntax, int extra_indent) |
4513 | 2105 { |
2106 switch (nda.ndims ()) | |
2107 { | |
2108 case 1: | |
2109 case 2: | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19318
diff
changeset
|
2110 octave_print_internal (os, Matrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2111 pr_as_read_syntax, extra_indent); |
4513 | 2112 break; |
2113 | |
2114 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2115 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax); |
4513 | 2116 break; |
2117 } | |
2118 } | |
2119 | |
5030 | 2120 template <> |
6018 | 2121 /* static */ inline void |
6015 | 2122 pr_plus_format<> (std::ostream& os, const Complex& c) |
3248 | 2123 { |
2124 double rp = c.real (); | |
2125 double ip = c.imag (); | |
2126 | |
2127 if (rp == 0.0) | |
2128 { | |
2129 if (ip == 0.0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2130 os << " "; |
3248 | 2131 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2132 os << "i"; |
3248 | 2133 } |
2134 else if (ip == 0.0) | |
3608 | 2135 pr_plus_format (os, rp); |
3248 | 2136 else |
2137 os << "c"; | |
2138 } | |
2139 | |
1 | 2140 void |
3523 | 2141 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
|
2142 bool pr_as_read_syntax) |
1 | 2143 { |
17867
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2144 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
|
2145 os << c; |
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2146 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
|
2147 pr_plus_format (os, c); |
1 | 2148 else |
2149 { | |
2150 set_format (c); | |
2151 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2152 os << c; |
1 | 2153 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2154 pr_complex (os, c); |
1 | 2155 } |
2156 } | |
2157 | |
2158 void | |
3523 | 2159 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
|
2160 bool pr_as_read_syntax, int extra_indent) |
1 | 2161 { |
5275 | 2162 octave_idx_type nr = cm.rows (); |
2163 octave_idx_type nc = cm.columns (); | |
1 | 2164 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2165 if (nr == 0 || nc == 0) |
626 | 2166 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
2167 else if (plus_format && ! pr_as_read_syntax) | |
1 | 2168 { |
5275 | 2169 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
|
2170 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2171 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
|
2172 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2173 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2174 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2175 pr_plus_format (os, cm(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2176 } |
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 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2179 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2180 } |
1 | 2181 } |
2182 else | |
2183 { | |
2184 int r_fw, i_fw; | |
3105 | 2185 double scale = 1.0; |
2186 set_format (cm, r_fw, i_fw, scale); | |
1 | 2187 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
|
2188 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
|
2189 || bit_format) ? 2 : 7; |
5275 | 2190 octave_idx_type total_width = nc * column_width; |
2191 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 2192 |
626 | 2193 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2194 max_width -= 4; |
1972 | 2195 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2196 max_width -= extra_indent; |
1972 | 2197 |
2198 if (max_width < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2199 max_width = 0; |
626 | 2200 |
1 | 2201 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2202 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2203 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2204 os << "[\n"; |
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 os << cm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2207 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2208 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2209 os << "]"; |
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 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2212 } |
1 | 2213 |
5275 | 2214 octave_idx_type inc = nc; |
2165 | 2215 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
|
2216 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2217 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2218 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2219 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2220 } |
1 | 2221 |
626 | 2222 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2223 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2224 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
|
2225 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2226 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2227 while (col < nc) |
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 lim = col + inc < nc ? col + inc : nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2230 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2231 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
|
2232 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2233 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2234 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2235 if (i == 0 && j == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2236 os << "[ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2237 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2238 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2239 if (j > col && j < lim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2240 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2241 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2242 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2243 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2244 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2245 pr_complex (os, cm(i,j)); |
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 col += inc; |
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 if (col >= nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2251 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2252 if (i == nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2253 os << " ]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2254 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2255 os << ";\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2256 } |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2261 } |
626 | 2262 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2263 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2264 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
|
2265 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2266 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2267 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2268 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
|
2269 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2270 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
|
2271 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2272 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
|
2273 extra_indent); |
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 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
|
2276 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2277 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2278 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2279 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
|
2280 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2281 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2282 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2283 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2284 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2285 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
|
2286 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2287 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2288 if (i < nr - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2289 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2290 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2291 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2292 } |
1 | 2293 } |
2294 } | |
2295 | |
2296 void | |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2297 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
|
2298 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2299 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2300 octave_idx_type nr = cm.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2301 octave_idx_type nc = cm.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2302 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2303 if (nr == 0 || nc == 0) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2304 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
|
2305 else if (plus_format && ! pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2306 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2307 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
|
2308 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2309 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
|
2310 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2311 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2312 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2313 pr_plus_format (os, cm(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2314 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2315 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2316 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2317 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2318 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2319 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2320 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2321 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2322 int r_fw, i_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2323 double scale = 1.0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2324 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
|
2325 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
|
2326 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
|
2327 || bit_format) ? 2 : 7; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2328 octave_idx_type total_width = nc * column_width; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2329 octave_idx_type max_width = command_editor::terminal_cols (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2330 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2331 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2332 max_width -= 4; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2333 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2334 max_width -= extra_indent; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2335 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2336 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2337 max_width = 0; |
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 (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2340 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2341 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2342 os << "[\n"; |
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 os << ComplexMatrix (cm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2345 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2346 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2347 os << "]"; |
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 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2350 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2351 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2352 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2353 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
|
2354 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2355 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2356 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2357 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2358 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2359 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2360 if (pr_as_read_syntax) |
10315
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 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2363 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2364 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2365 while (col < nc) |
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 lim = col + inc < nc ? col + inc : nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2368 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2369 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2370 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2371 octave_quit (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2372 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2373 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2374 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2375 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2376 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2377 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2378 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2379 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2380 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2381 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2382 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2383 pr_complex (os, cm(j,j)); |
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 col += inc; |
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 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2389 os << " ]"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2390 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2391 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2392 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2393 os << ")"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2394 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2395 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2396 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2397 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
|
2398 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2399 os << "Diagonal Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2400 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2401 os << "\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2402 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2403 pr_scale_header (os, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2404 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2405 // kluge. Get the true width of a number. |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2406 int zero_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2407 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2408 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2409 std::ostringstream tmp_oss; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2410 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
|
2411 zero_fw = tmp_oss.str ().length (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2412 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2413 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2414 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
|
2415 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2416 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
|
2417 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2418 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
|
2419 extra_indent); |
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 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
|
2422 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2423 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2424 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2425 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
|
2426 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2427 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2428 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2429 os << " "; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2430 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2431 if (i == j) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2432 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
|
2433 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2434 os << std::setw (zero_fw) << '0'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2435 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2436 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2437 if (i < nr - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2438 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2439 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2440 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2441 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2442 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2443 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2444 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2445 void |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2446 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
|
2447 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
|
2448 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2449 octave_idx_type nr = m.rows (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2450 octave_idx_type nc = m.columns (); |
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 if (nr == 0 || nc == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2453 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
|
2454 else if (plus_format && ! pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2455 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2456 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
|
2457 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2458 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
|
2459 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2460 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2461 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2462 pr_plus_format (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2463 } |
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 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2466 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2467 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2468 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2469 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2470 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2471 int fw = 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2472 int column_width = fw + 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2473 octave_idx_type total_width = nc * column_width; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2474 octave_idx_type max_width = command_editor::terminal_cols (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2475 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2476 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2477 max_width -= 4; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2478 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2479 max_width -= extra_indent; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2480 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2481 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2482 max_width = 0; |
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 (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2485 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2486 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2487 os << "[\n"; |
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 os << Matrix (m); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2490 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2491 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2492 os << "]"; |
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 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2495 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2496 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2497 octave_idx_type inc = nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2498 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
|
2499 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2500 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2501 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2502 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2503 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2504 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2505 if (pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2506 { |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18816
diff
changeset
|
2507 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
|
2508 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2509 os << "eye ("; |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18816
diff
changeset
|
2510 os << ":, "; |
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 octave_idx_type col = 0; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2513 while (col < nc) |
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 lim = col + inc < nc ? col + inc : nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2516 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2517 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
|
2518 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2519 octave_quit (); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2520 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2521 if (j == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2522 os << "[ "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2523 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2524 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2525 if (j > col && j < lim) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2526 os << ", "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2527 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2528 os << " "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2529 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2530 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2531 os << pvec (j); |
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 col += inc; |
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 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2537 os << " ]"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2538 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2539 os << " ...\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2540 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2541 os << ")"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2542 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2543 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2544 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2545 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
|
2546 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2547 os << "Permutation Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2548 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2549 os << "\n"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2550 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2551 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
|
2552 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2553 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
|
2554 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2555 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
|
2556 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2557 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2558 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
|
2559 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2560 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2561 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2562 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
|
2563 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2564 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2565 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2566 os << " "; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2567 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2568 os << std::setw (fw) << m(i,j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2569 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2570 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2571 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2572 os << "\n"; |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2575 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2576 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2577 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2578 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2579 void |
4513 | 2580 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
|
2581 bool pr_as_read_syntax, int extra_indent) |
4513 | 2582 { |
2583 switch (nda.ndims ()) | |
2584 { | |
2585 case 1: | |
2586 case 2: | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19318
diff
changeset
|
2587 octave_print_internal (os, ComplexMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2588 pr_as_read_syntax, extra_indent); |
4513 | 2589 break; |
2590 | |
2591 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2592 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
|
2593 (os, nda, pr_as_read_syntax); |
4513 | 2594 break; |
2595 } | |
2596 } | |
2597 | |
2598 void | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2599 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
|
2600 { |
21583
d5963a6e29c2
Use integer output formatting for logicals (bug #47607)
Mike Miller <mtmiller@octave.org>
parents:
21568
diff
changeset
|
2601 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
|
2602 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2603 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2604 // 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
|
2605 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2606 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2607 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
|
2608 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2609 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
|
2610 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2611 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2612 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2613 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
|
2614 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
|
2615 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2616 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
|
2617 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2618 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2619 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2620 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
|
2621 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
|
2622 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2623 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
|
2624 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2625 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2626 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2627 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
|
2628 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
|
2629 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2630 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
|
2631 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2632 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2633 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2634 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
|
2635 bool pr_as_read_syntax) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2636 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2637 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
|
2638 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2639 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2640 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2641 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
|
2642 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
|
2643 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2644 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
|
2645 extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2646 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2647 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2648 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2649 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
|
2650 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2651 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2652 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
|
2653 extra_indent); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2654 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2655 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2656 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2657 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
|
2658 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
|
2659 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2660 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
|
2661 extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2662 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2663 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2664 void |
3523 | 2665 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
|
2666 bool pr_as_read_syntax, int extra_indent) |
1 | 2667 { |
626 | 2668 double base = r.base (); |
1 | 2669 double increment = r.inc (); |
626 | 2670 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
|
2671 octave_idx_type num_elem = r.numel (); |
1 | 2672 |
626 | 2673 if (plus_format && ! pr_as_read_syntax) |
1 | 2674 { |
5275 | 2675 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
|
2676 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2677 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2678 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2679 double val = base + i * increment; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2680 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2681 pr_plus_format (os, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2682 } |
1 | 2683 } |
2684 else | |
2685 { | |
10987
eec74ee00b32
eliminate some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2686 int fw = 0; |
3105 | 2687 double scale = 1.0; |
2688 set_format (r, fw, scale); | |
1 | 2689 |
626 | 2690 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2691 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2692 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2693 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2694 os << base << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2695 if (increment != 1.0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2696 os << increment << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2697 os << limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2698 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2699 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2700 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2701 pr_float (os, base, fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2702 os << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2703 if (increment != 1.0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2704 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2705 pr_float (os, increment, fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2706 os << " : "; |
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, limit, fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2709 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2710 } |
626 | 2711 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2712 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2713 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
|
2714 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2715 int column_width = fw + 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2716 octave_idx_type total_width = num_elem * column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2717 octave_idx_type max_width = command_editor::terminal_cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2718 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2719 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2720 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2721 os << r; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2722 return; |
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2725 octave_idx_type inc = num_elem; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2726 if (total_width > max_width && Vsplit_long_rows) |
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 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2729 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2730 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2731 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2732 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2733 max_width -= extra_indent; |
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 if (max_width < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2736 max_width = 0; |
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 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2739 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2740 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2741 while (col < num_elem) |
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 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
|
2744 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2745 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
|
2746 extra_indent); |
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 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2749 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2750 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
|
2751 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2752 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2753 |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2754 double val; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2755 if (i == 0) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2756 val = base; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2757 else |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2758 val = base + i * increment; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2759 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2760 if (i == num_elem - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2761 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2762 // 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
|
2763 if ((increment > 0 && val >= limit) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2764 || (increment < 0 && val <= limit)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2765 val = limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2766 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2767 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2768 os << " "; |
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 pr_float (os, val, fw, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2771 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2772 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2773 col += inc; |
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 } |
1 | 2776 } |
2777 } | |
2778 | |
1343 | 2779 void |
3523 | 2780 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
|
2781 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2782 int extra_indent) |
3215 | 2783 { |
21583
d5963a6e29c2
Use integer output formatting for logicals (bug #47607)
Mike Miller <mtmiller@octave.org>
parents:
21568
diff
changeset
|
2784 uint8NDArray tmp (bm); |
3215 | 2785 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); |
2786 } | |
2787 | |
2788 void | |
4513 | 2789 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
|
2790 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2791 int extra_indent) |
4513 | 2792 { |
2793 switch (nda.ndims ()) | |
2794 { | |
2795 case 1: | |
2796 case 2: | |
19317
25f535b90e52
Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.
Carnë Draug <carandraug@octave.org>
parents:
19255
diff
changeset
|
2797 octave_print_internal (os, boolMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2798 pr_as_read_syntax, extra_indent); |
4513 | 2799 break; |
2800 | |
2801 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2802 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
|
2803 boolMatrix> (os, nda, pr_as_read_syntax); |
4513 | 2804 break; |
2805 } | |
2806 } | |
2807 | |
2808 void | |
3523 | 2809 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
|
2810 bool pr_as_read_syntax, |
21066
258c787cd9ce
maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
2811 int /* FIXME: extra_indent */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2812 bool pr_as_string) |
1343 | 2813 { |
1572 | 2814 if (pr_as_string) |
2815 { | |
5275 | 2816 octave_idx_type nstr = chm.rows (); |
1343 | 2817 |
1572 | 2818 if (pr_as_read_syntax && nstr > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2819 os << "[ "; |
1343 | 2820 |
2907 | 2821 if (nstr != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2822 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2823 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
|
2824 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2825 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2826 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2827 std::string row = chm.row_as_string (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2828 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2829 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2830 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2831 os << "\"" << undo_string_escapes (row) << "\""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2832 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2833 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2834 os << "; "; |
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 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2837 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2838 os << row; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2839 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2840 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2841 os << "\n"; |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2844 } |
1572 | 2845 |
2846 if (pr_as_read_syntax && nstr > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2847 os << " ]"; |
1343 | 2848 } |
1572 | 2849 else |
2850 { | |
2851 os << "sorry, printing char matrices not implemented yet\n"; | |
2852 } | |
1343 | 2853 } |
2854 | |
4513 | 2855 void |
2856 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
|
2857 bool pr_as_read_syntax, int extra_indent, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2858 bool pr_as_string) |
4513 | 2859 { |
2860 switch (nda.ndims ()) | |
2861 { | |
2862 case 1: | |
2863 case 2: | |
19318
6c9ea5be96bf
Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents:
19317
diff
changeset
|
2864 octave_print_internal (os, charMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2865 pr_as_read_syntax, extra_indent, pr_as_string); |
4513 | 2866 break; |
2867 | |
2868 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2869 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
|
2870 pr_as_read_syntax); |
4513 | 2871 break; |
2872 } | |
2873 } | |
2874 | |
4655 | 2875 void |
4925 | 2876 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
|
2877 bool pr_as_read_syntax, int extra_indent) |
4925 | 2878 { |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2879 Array<std::string> nda (dim_vector (1, 1), s); |
4925 | 2880 |
2881 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent); | |
2882 } | |
2883 | |
2884 void | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2885 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
|
2886 bool pr_as_read_syntax, int /* extra_indent */) |
4655 | 2887 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2888 // FIXME: this mostly duplicates the code in the print_nd_array<> |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2889 // function. Can fix this with std::is_same from C++11. |
4655 | 2890 |
2891 if (nda.is_empty ()) | |
2892 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
|
2893 else if (nda.numel () == 1) |
4655 | 2894 { |
2895 os << nda(0); | |
2896 } | |
2897 else | |
2898 { | |
2899 int ndims = nda.ndims (); | |
2900 | |
2901 dim_vector dims = nda.dims (); | |
2902 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2903 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 2904 |
2905 octave_idx_type m = 1; | |
4655 | 2906 |
2907 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2908 m *= dims(i); |
4655 | 2909 |
5275 | 2910 octave_idx_type nr = dims(0); |
2911 octave_idx_type nc = dims(1); | |
2912 | |
2913 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
|
2914 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2915 std::string nm = "ans"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2916 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2917 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2918 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2919 nm += "(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2920 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2921 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2922 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2923 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2924 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2925 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2926 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2927 if (k < ndims - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2928 buf << ","; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2929 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2930 buf << ")"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2931 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2932 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2933 nm += buf.str (); |
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 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2936 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
|
2937 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2938 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2939 idx(1) = idx_vector (':'); |
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 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2942 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2943 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2944 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
|
2945 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2946 // 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
|
2947 // in neatly aligned columns... |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2948 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2949 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2950 octave_idx_type n_cols = page.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2951 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2952 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2953 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2954 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2955 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2956 for (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
|
2957 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2958 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
|
2959 os << " " << page(ii,jj); |
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 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2962 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2963 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2964 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2965 os << "\n"; |
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) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2968 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2969 } |
4655 | 2970 } |
2971 } | |
2972 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
2973 template <typename T> |
4901 | 2974 class |
2975 octave_print_conv | |
2976 { | |
2977 public: | |
2978 typedef T print_conv_type; | |
2979 }; | |
2980 | |
2981 #define PRINT_CONV(T1, T2) \ | |
2982 template <> \ | |
2983 class \ | |
2984 octave_print_conv<T1> \ | |
2985 { \ | |
2986 public: \ | |
2987 typedef T2 print_conv_type; \ | |
2988 } | |
2989 | |
2990 PRINT_CONV (octave_int8, octave_int16); | |
2991 PRINT_CONV (octave_uint8, octave_uint16); | |
2992 | |
2993 #undef PRINT_CONV | |
2994 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
2995 template <typename T> |
6018 | 2996 /* static */ inline void |
4949 | 2997 pr_int (std::ostream& os, const T& d, int fw = 0) |
2998 { | |
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
|
2999 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
|
3000 const unsigned char * tmpi = d.iptr (); |
4949 | 3001 |
5544 | 3002 // Unless explicitly asked for, always print in big-endian |
3003 // format for hex and bit formats. | |
3004 // | |
3005 // {bit,hex}_format == 1: print big-endian | |
3006 // {bit,hex}_format == 2: print native | |
3007 | |
4949 | 3008 if (hex_format) |
3009 { | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3010 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
|
3011 |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3012 os.flags (std::ios::right | std::ios::hex); |
4949 | 3013 |
3014 if (hex_format > 1 || oct_mach_info::words_big_endian ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3015 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3016 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3017 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
|
3018 } |
4949 | 3019 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3020 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3021 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3022 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
|
3023 } |
4949 | 3024 } |
3025 else if (bit_format) | |
3026 { | |
5544 | 3027 if (oct_mach_info::words_big_endian ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3028 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3029 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3030 PRINT_CHAR_BITS (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3031 } |
4949 | 3032 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3033 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3034 if (bit_format > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3035 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3036 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3037 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); |
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 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3040 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3041 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3042 PRINT_CHAR_BITS (os, tmpi[i]); |
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 } |
4949 | 3045 } |
3046 else | |
3047 { | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3048 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
|
3049 |
4949 | 3050 os << std::setw (fw) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3051 << typename octave_print_conv<T>::print_conv_type (d); |
4949 | 3052 |
3053 if (bank_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3054 os << ".00"; |
4949 | 3055 } |
3056 } | |
3057 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3058 // FIXME: all this mess with abs is an attempt to avoid seeing |
6120 | 3059 // |
3060 // warning: comparison of unsigned expression < 0 is always false | |
3061 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3062 // from GCC. Isn't there a better way? |
6120 | 3063 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3064 template <typename T> |
6018 | 3065 /* static */ inline T |
6008 | 3066 abs (T x) |
3067 { | |
6120 | 3068 return x < 0 ? -x : x; |
6008 | 3069 } |
3070 | |
6120 | 3071 #define INSTANTIATE_ABS(T) \ |
12414 | 3072 template /* static */ T abs (T) |
6120 | 3073 |
3074 INSTANTIATE_ABS(signed char); | |
3075 INSTANTIATE_ABS(short); | |
3076 INSTANTIATE_ABS(int); | |
3077 INSTANTIATE_ABS(long); | |
3078 INSTANTIATE_ABS(long long); | |
3079 | |
3080 #define SPECIALIZE_UABS(T) \ | |
3081 template <> \ | |
3082 /* static */ inline unsigned T \ | |
3083 abs (unsigned T x) \ | |
3084 { \ | |
3085 return x; \ | |
3086 } | |
3087 | |
3088 SPECIALIZE_UABS(char) | |
3089 SPECIALIZE_UABS(short) | |
3090 SPECIALIZE_UABS(int) | |
3091 SPECIALIZE_UABS(long) | |
3092 SPECIALIZE_UABS(long long) | |
6008 | 3093 |
7215 | 3094 template void |
3095 pr_int (std::ostream&, const octave_int8&, int); | |
3096 | |
3097 template void | |
3098 pr_int (std::ostream&, const octave_int16&, int); | |
3099 | |
3100 template void | |
3101 pr_int (std::ostream&, const octave_int32&, int); | |
3102 | |
3103 template void | |
3104 pr_int (std::ostream&, const octave_int64&, int); | |
3105 | |
3106 template void | |
3107 pr_int (std::ostream&, const octave_uint8&, int); | |
3108 | |
3109 template void | |
3110 pr_int (std::ostream&, const octave_uint16&, int); | |
3111 | |
3112 template void | |
3113 pr_int (std::ostream&, const octave_uint32&, int); | |
3114 | |
3115 template void | |
3116 pr_int (std::ostream&, const octave_uint64&, int); | |
3117 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3118 template <typename T> |
4901 | 3119 void |
7215 | 3120 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
|
3121 bool) |
7215 | 3122 { |
3123 if (plus_format) | |
3124 { | |
3125 pr_plus_format (os, val); | |
3126 } | |
3127 else | |
3128 { | |
3129 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3130 os << typename octave_print_conv<octave_int<T> >::print_conv_type (val); |
7215 | 3131 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3132 pr_int (os, val); |
7215 | 3133 } |
3134 } | |
3135 | |
3136 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ | |
3137 OCTINTERP_API void \ | |
3138 octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \ | |
3139 { \ | |
3140 octave_print_internal_template (os, val, dummy); \ | |
3141 } | |
3142 | |
3143 PRINT_INT_SCALAR_INTERNAL (int8_t) | |
3144 PRINT_INT_SCALAR_INTERNAL (uint8_t) | |
3145 PRINT_INT_SCALAR_INTERNAL (int16_t) | |
3146 PRINT_INT_SCALAR_INTERNAL (uint16_t) | |
3147 PRINT_INT_SCALAR_INTERNAL (int32_t) | |
3148 PRINT_INT_SCALAR_INTERNAL (uint32_t) | |
3149 PRINT_INT_SCALAR_INTERNAL (int64_t) | |
3150 PRINT_INT_SCALAR_INTERNAL (uint64_t) | |
3151 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3152 template <typename T> |
7215 | 3153 /* static */ inline void |
3154 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
|
3155 bool pr_as_read_syntax, int extra_indent) |
4901 | 3156 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3157 // FIXME: this mostly duplicates the code in the print_nd_array<> |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
3158 // function. Can fix this with std::is_same from C++11. |
4901 | 3159 |
3160 if (nda.is_empty ()) | |
3161 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
|
3162 else if (nda.numel () == 1) |
7215 | 3163 octave_print_internal_template (os, nda(0), pr_as_read_syntax); |
4949 | 3164 else if (plus_format && ! pr_as_read_syntax) |
4901 | 3165 { |
3166 int ndims = nda.ndims (); | |
3167 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3168 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
4949 | 3169 |
4901 | 3170 dim_vector dims = nda.dims (); |
3171 | |
5275 | 3172 octave_idx_type m = 1; |
4901 | 3173 |
3174 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3175 m *= dims(i); |
4901 | 3176 |
5275 | 3177 octave_idx_type nr = dims(0); |
3178 octave_idx_type nc = dims(1); | |
3179 | |
3180 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
|
3181 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3182 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3183 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3184 std::string nm = "ans(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3185 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3186 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3187 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3188 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3189 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3190 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3191 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3192 if (k < ndims - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3193 buf << ","; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3194 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3195 buf << ")"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3196 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3197 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3198 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3199 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3200 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3201 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3202 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3203 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3204 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3205 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
|
3206 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3207 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3208 idx(1) = idx_vector (':'); |
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 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3211 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3212 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3213 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
|
3214 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3215 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
|
3216 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3217 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
|
3218 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3219 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3220 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3221 pr_plus_format (os, page(ii,jj)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3222 } |
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 if ((ii < nr - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3225 os << "\n"; |
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3228 if (i < m - 1) |
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 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3231 increment_index (ra_idx, dims, 2); |
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 } |
4949 | 3234 } |
3235 else | |
3236 { | |
3237 int ndims = nda.ndims (); | |
3238 | |
3239 dim_vector dims = nda.dims (); | |
3240 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3241 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 3242 |
3243 octave_idx_type m = 1; | |
4949 | 3244 |
3245 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3246 m *= dims(i); |
4949 | 3247 |
5275 | 3248 octave_idx_type nr = dims(0); |
3249 octave_idx_type nc = dims(1); | |
4949 | 3250 |
3251 int fw = 0; | |
3252 if (hex_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3253 fw = 2 * nda(0).byte_size (); |
4949 | 3254 else if (bit_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3255 fw = nda(0).nbits (); |
4949 | 3256 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3257 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3258 bool isneg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3259 int digits = 0; |
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 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
|
3262 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3263 int new_digits |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3264 = static_cast<int> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3265 (gnulib::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
|
3266 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3267 if (new_digits > digits) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3268 digits = new_digits; |
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 (! isneg) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3271 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
|
3272 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3273 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3274 fw = digits + isneg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3275 } |
4949 | 3276 |
6788 | 3277 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2)); |
5275 | 3278 octave_idx_type total_width = nc * column_width; |
4949 | 3279 int max_width = command_editor::terminal_cols () - extra_indent; |
5275 | 3280 octave_idx_type inc = nc; |
4949 | 3281 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
|
3282 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3283 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3284 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3285 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3286 } |
4949 | 3287 |
5275 | 3288 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
|
3289 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3290 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3291 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3292 std::string nm = "ans(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3293 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3294 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3295 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3296 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3297 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3298 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3299 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3300 if (k < ndims - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3301 buf << ","; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3302 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3303 buf << ")"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3304 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3305 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3306 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3307 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3308 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3309 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3310 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3311 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3312 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3313 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
|
3314 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3315 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3316 idx(1) = idx_vector (':'); |
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 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3319 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3320 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3321 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
|
3322 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3323 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3324 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3325 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3326 os << "[\n"; |
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 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
|
3329 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3330 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
|
3331 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3332 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3333 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3334 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
|
3335 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3336 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3337 } |
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 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3340 os << "]"; |
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 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3343 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3344 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
|
3345 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3346 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3347 octave_idx_type n_cols = page.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3348 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3349 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
|
3350 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3351 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
|
3352 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3353 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
|
3354 extra_indent); |
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 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
|
3357 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3358 os << std::setw (extra_indent) << ""; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3359 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3360 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
|
3361 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3362 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3363 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3364 pr_int (os, page(ii,jj), fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3365 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3366 if ((ii < n_rows - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3367 os << "\n"; |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3370 } |
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 if (i < m - 1) |
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 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3375 increment_index (ra_idx, dims, 2); |
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 } |
4901 | 3378 } |
3379 } | |
3380 | |
7215 | 3381 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \ |
3382 OCTINTERP_API void \ | |
3383 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3384 bool pr_as_read_syntax, int extra_indent) \ |
7215 | 3385 { \ |
3386 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \ | |
3387 } | |
3388 | |
3389 PRINT_INT_ARRAY_INTERNAL (octave_int8) | |
3390 PRINT_INT_ARRAY_INTERNAL (octave_uint8) | |
3391 PRINT_INT_ARRAY_INTERNAL (octave_int16) | |
3392 PRINT_INT_ARRAY_INTERNAL (octave_uint16) | |
3393 PRINT_INT_ARRAY_INTERNAL (octave_int32) | |
3394 PRINT_INT_ARRAY_INTERNAL (octave_uint32) | |
3395 PRINT_INT_ARRAY_INTERNAL (octave_int64) | |
3396 PRINT_INT_ARRAY_INTERNAL (octave_uint64) | |
4901 | 3397 |
8012
63dbb85452cc
fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents:
7896
diff
changeset
|
3398 void |
3933 | 3399 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) |
3928 | 3400 { |
3933 | 3401 panic_impossible (); |
3928 | 3402 } |
3403 | |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3404 void |
19620
a1d172bfcb2f
eliminate some unused variable and typedef warnings
John W. Eaton <jwe@octave.org>
parents:
19367
diff
changeset
|
3405 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
|
3406 { |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3407 panic_impossible (); |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3408 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3409 |
20915
a3359fe50966
remove unused nargout variables
John W. Eaton <jwe@octave.org>
parents:
20909
diff
changeset
|
3410 DEFUN (rats, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3411 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
3412 @deftypefn {} {} rats (@var{x}, @var{len})\n\ |
6788 | 3413 Convert @var{x} into a rational approximation represented as a string.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3414 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3415 The string can be converted back into a matrix as follows:\n\ |
6788 | 3416 \n\ |
3417 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3418 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3419 r = rats (hilb (4));\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3420 x = str2num (r)\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3421 @end group\n\ |
6788 | 3422 @end example\n\ |
3423 \n\ | |
3424 The optional second argument defines the maximum length of the string\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8930
diff
changeset
|
3425 representing the elements of @var{x}. By default @var{len} is 9.\n\ |
19363
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
3426 \n\ |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
3427 If the length of the smallest possible rational approximation exceeds\n\ |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
3428 @var{len}, an asterisk (*) padded with spaces will be returned instead.\n\ |
6788 | 3429 @seealso{format, rat}\n\ |
3430 @end deftypefn") | |
3431 { | |
3432 int nargin = args.length (); | |
3433 | |
20909
03e4ddd49396
omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents:
20897
diff
changeset
|
3434 if (nargin < 1 || nargin > 2) |
7896 | 3435 print_usage (); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3436 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3437 octave_value arg = args(0); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3438 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3439 if (! arg.is_numeric_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3440 error ("rats: X must be numeric"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3441 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3442 unwind_protect frame; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3443 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3444 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
|
3445 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3446 rat_string_len = 9; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3447 if (nargin == 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3448 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
|
3449 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3450 frame.protect_var (rat_format); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3451 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3452 rat_format = true; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3453 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3454 std::ostringstream buf; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3455 arg.print (buf); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3456 std::string s = buf.str (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3457 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3458 std::list<std::string> lst; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3459 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3460 size_t n = 0; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3461 size_t s_len = s.length (); |
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 while (n < s_len) |
6788 | 3464 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3465 size_t m = s.find ('\n', n); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3466 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3467 if (m == std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3468 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3469 lst.push_back (s.substr (n)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3470 break; |
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 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3473 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3474 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
|
3475 n = m + 1; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3476 } |
6788 | 3477 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3478 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3479 return ovl (string_vector (lst)); |
6788 | 3480 } |
3481 | |
3685 | 3482 DEFUN (disp, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3483 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
3484 @deftypefn {} {} disp (@var{x})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3485 Display the value of @var{x}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3486 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3487 For example:\n\ |
3685 | 3488 \n\ |
3489 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3490 @group\n\ |
3685 | 3491 disp (\"The value of pi is:\"), disp (pi)\n\ |
3492 \n\ | |
3493 @print{} the value of pi is:\n\ | |
3494 @print{} 3.1416\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3495 @end group\n\ |
3685 | 3496 @end example\n\ |
3497 \n\ | |
3498 @noindent\n\ | |
3499 Note that the output from @code{disp} always ends with a newline.\n\ | |
3500 \n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3501 If an output value is requested, @code{disp} prints nothing and returns the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3502 formatted output in a string.\n\ |
5642 | 3503 @seealso{fdisp}\n\ |
3504 @end deftypefn") | |
3685 | 3505 { |
20909
03e4ddd49396
omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents:
20897
diff
changeset
|
3506 if (args.length () != 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3507 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3508 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3509 octave_value_list retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3510 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3511 octave_value arg = args(0); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3512 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3513 if (nargout == 0) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3514 arg.print (octave_stdout); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3515 else |
3685 | 3516 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3517 std::ostringstream buf; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3518 arg.print (buf); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3519 retval = octave_value (buf.str (), arg.is_dq_string () ? '"' : '\''); |
3685 | 3520 } |
3521 | |
3522 return retval; | |
3523 } | |
3524 | |
3525 DEFUN (fdisp, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3526 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
3527 @deftypefn {} {} fdisp (@var{fid}, @var{x})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3528 Display the value of @var{x} on the stream @var{fid}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3529 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3530 For example:\n\ |
3685 | 3531 \n\ |
3532 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3533 @group\n\ |
4869 | 3534 fdisp (stdout, \"The value of pi is:\"), fdisp (stdout, pi)\n\ |
3685 | 3535 \n\ |
3536 @print{} the value of pi is:\n\ | |
3537 @print{} 3.1416\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3538 @end group\n\ |
3685 | 3539 @end example\n\ |
3540 \n\ | |
3541 @noindent\n\ | |
4869 | 3542 Note that the output from @code{fdisp} always ends with a newline.\n\ |
5642 | 3543 @seealso{disp}\n\ |
3544 @end deftypefn") | |
3685 | 3545 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
3546 if (args.length () != 2) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3547 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3548 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3549 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
|
3550 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3551 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
|
3552 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3553 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
|
3554 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3555 octave_value arg = args(1); |
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 if (osp) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3558 arg.print (*osp); |
3685 | 3559 else |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3560 error ("fdisp: stream FID not open for writing"); |
3685 | 3561 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
3562 return ovl (); |
3685 | 3563 } |
3564 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3565 /* |
9629 | 3566 %!test |
3567 %! format short | |
3568 %! fd = tmpfile (); | |
3569 %! for r = [0, Inf -Inf, NaN] | |
3570 %! for i = [0, Inf -Inf, NaN] | |
3571 %! fdisp (fd, complex (r, i)); | |
3572 %! endfor | |
3573 %! endfor | |
3574 %! fclose (fd); | |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3575 |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3576 %!test |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3577 %! foo.real = pi * ones (3,20,3); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3578 %! 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
|
3579 %! foo.char = repmat ("- Hello World -", [3, 20]); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3580 %! 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
|
3581 %! 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
|
3582 %! 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
|
3583 %! format loose; |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3584 %! 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
|
3585 %! format compact; |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3586 %! compact = disp (foo.(fields{f})); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3587 %! 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
|
3588 %! assert (expected, compact); |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3589 %! endfor |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3590 */ |
9629 | 3591 |
1 | 3592 static void |
3593 init_format_state (void) | |
3594 { | |
2387 | 3595 free_format = false; |
3596 plus_format = false; | |
6788 | 3597 rat_format = false; |
2387 | 3598 bank_format = false; |
3608 | 3599 hex_format = 0; |
1309 | 3600 bit_format = 0; |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3601 Vcompact_format = false; |
2387 | 3602 print_e = false; |
3603 print_big_e = false; | |
4509 | 3604 print_g = false; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3605 print_eng = false; |
1 | 3606 } |
3607 | |
3608 static void | |
3609 set_output_prec_and_fw (int prec, int fw) | |
3610 { | |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
3611 Voutput_precision = prec; |
5794 | 3612 Voutput_max_field_width = fw; |
1 | 3613 } |
3614 | |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3615 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
|
3616 |
1755 | 3617 static void |
3618 set_format_style (int argc, const string_vector& argv) | |
1 | 3619 { |
1755 | 3620 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
|
3621 std::string format; |
1755 | 3622 |
1899 | 3623 if (--argc > 0) |
1 | 3624 { |
3523 | 3625 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
|
3626 format = arg; |
2584 | 3627 |
1755 | 3628 if (arg == "short") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3629 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3630 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3631 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3632 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
|
3633 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3634 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3635 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3636 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3637 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3638 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3639 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3640 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3641 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3642 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3643 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3644 print_big_e = true; |
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 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3647 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3648 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3649 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3650 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3651 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3652 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3653 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3654 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3655 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3656 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3657 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3658 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3659 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3660 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3661 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3662 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3663 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
|
3664 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3665 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3666 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3667 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3668 set_output_prec_and_fw (5, 10); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3669 } |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3670 else if (arg == "shorte") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3671 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3672 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3673 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3674 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
|
3675 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3676 else if (arg == "shortE") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3677 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3678 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3679 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3680 print_big_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3681 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
|
3682 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3683 else if (arg == "shortg") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3684 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3685 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3686 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3687 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
|
3688 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3689 else if (arg == "shortG") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3690 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3691 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3692 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3693 print_big_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3694 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
|
3695 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3696 else if (arg == "shortEng") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3697 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3698 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3699 print_eng = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3700 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
|
3701 } |
1755 | 3702 else if (arg == "long") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3703 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3704 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3705 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3706 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
|
3707 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3708 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3709 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3710 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3711 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3712 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3713 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3714 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3715 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3716 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3717 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3718 print_big_e = true; |
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 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3721 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3722 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3723 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3724 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3725 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3726 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3727 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3728 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3729 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3730 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3731 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3732 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3733 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3734 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3735 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3736 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3737 error ("format: unrecognized option 'long %s'", arg.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3738 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3739 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3740 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3741 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3742 set_output_prec_and_fw (15, 20); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3743 } |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3744 else if (arg == "longe") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3745 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3746 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3747 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3748 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
|
3749 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3750 else if (arg == "longE") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3751 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3752 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3753 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3754 print_big_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3755 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
|
3756 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3757 else if (arg == "longg") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3758 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3759 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3760 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3761 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
|
3762 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3763 else if (arg == "longG") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3764 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3765 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3766 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3767 print_big_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3768 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
|
3769 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3770 else if (arg == "longEng") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3771 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3772 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3773 print_eng = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3774 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
|
3775 } |
1755 | 3776 else if (arg == "hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3777 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3778 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3779 hex_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3780 } |
1755 | 3781 else if (arg == "native-hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3782 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3783 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3784 hex_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3785 } |
1755 | 3786 else if (arg == "bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3787 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3788 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3789 bit_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3790 } |
1755 | 3791 else if (arg == "native-bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3792 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3793 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3794 bit_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3795 } |
1755 | 3796 else if (arg == "+" || arg == "plus") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3797 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3798 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3799 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3800 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
|
3801 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3802 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3803 if (arg.length () == 3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3804 plus_format_chars = arg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3805 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3806 error ("format: invalid option for plus format"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3807 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3808 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
|
3809 plus_format_chars = "+- "; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3810 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3811 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3812 plus_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3813 } |
6788 | 3814 else if (arg == "rat") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3815 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3816 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3817 rat_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3818 } |
1755 | 3819 else if (arg == "bank") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3820 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3821 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3822 bank_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3823 } |
1755 | 3824 else if (arg == "free") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3825 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3826 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3827 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3828 } |
1755 | 3829 else if (arg == "none") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3830 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3831 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3832 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3833 } |
1755 | 3834 else if (arg == "compact") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3835 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3836 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
|
3837 return; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3838 } |
1755 | 3839 else if (arg == "loose") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3840 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3841 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
|
3842 return; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3843 } |
1 | 3844 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3845 error ("format: unrecognized format state '%s'", arg.c_str ()); |
1 | 3846 } |
3847 else | |
3848 { | |
3849 init_format_state (); | |
3850 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
|
3851 format = std::string ("short"); |
1 | 3852 } |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3853 |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3854 format_string = format; |
1 | 3855 } |
3856 | |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3857 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8625
diff
changeset
|
3858 DEFUN (format, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3859 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
3860 @deftypefn {} {} format\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
3861 @deftypefnx {} {} format options\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3862 Reset or specify the format of the output produced by @code{disp} and\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3863 Octave's normal echoing mechanism.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3864 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3865 This command only affects the display of numbers but not how they are stored\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3866 or computed. To change the internal representation from the default double\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3867 use one of the conversion functions such as @code{single}, @code{uint8},\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3868 @code{int64}, etc.\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3869 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3870 By default, Octave displays 5 significant digits in a human readable form\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3871 (option @samp{short} paired with @samp{loose} format for matrices).\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3872 If @code{format} is invoked without any options, this default format\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3873 is restored.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3874 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3875 Valid formats for floating point numbers are listed in the following\n\ |
3372 | 3876 table.\n\ |
3877 \n\ | |
3878 @table @code\n\ | |
3879 @item short\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3880 Fixed point format with 5 significant figures in a field that is a maximum\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3881 of 10 characters wide. (default).\n\ |
3372 | 3882 \n\ |
3883 If Octave is unable to format a matrix so that columns line up on the\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3884 decimal point and all numbers fit within the maximum field width then\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3885 it switches to an exponential @samp{e} format.\n\ |
3372 | 3886 \n\ |
3887 @item long\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3888 Fixed point format with 15 significant figures in a field that is a maximum\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3889 of 20 characters wide.\n\ |
3372 | 3890 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3891 As with the @samp{short} format, Octave will switch to an exponential\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3892 @samp{e} format if it is unable to format a matrix properly using the\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3893 current format.\n\ |
3372 | 3894 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3895 @item short e\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3896 @itemx long e\n\ |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
3897 Exponential format. The number to be represented is split between a\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
3898 mantissa and an exponent (power of 10). The mantissa has 5 significant\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
3899 digits in the short format and 15 digits in the long format. For example,\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
3900 with the @samp{short e} format, @code{pi} is displayed as\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3901 @code{3.1416e+00}.\n\ |
3372 | 3902 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3903 @item short E\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3904 @itemx long E\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3905 Identical to @samp{short e} or @samp{long e} but displays an uppercase\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3906 @samp{E} to indicate the exponent.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3907 For example, with the @samp{long E} format, @code{pi} is displayed as\n\ |
3372 | 3908 @code{3.14159265358979E+00}.\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3909 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3910 @item short g\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3911 @itemx long g\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3912 Optimally choose between fixed point and exponential format based on\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3913 the magnitude of the number.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3914 For example, with the @samp{short g} format,\n\ |
4509 | 3915 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ |
3916 \n\ | |
3917 @example\n\ | |
3918 @group\n\ | |
3919 ans =\n\ | |
3920 \n\ | |
3921 9.8696\n\ | |
3922 97.409\n\ | |
3923 9488.5\n\ | |
3924 9.0032e+07\n\ | |
3925 8.1058e+15\n\ | |
3926 @end group\n\ | |
3927 @end example\n\ | |
3928 \n\ | |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3929 @item short eng\n\ |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3930 @itemx long eng\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3931 Identical to @samp{short e} or @samp{long e} but displays the value\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3932 using an engineering format, where the exponent is divisible by 3. For\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3933 example, with the @samp{short eng} format, @code{10 * pi} is displayed as\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3934 @code{31.4159e+00}.\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3935 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3936 @item long G\n\ |
4509 | 3937 @itemx short G\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3938 Identical to @samp{short g} or @samp{long g} but displays an uppercase\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3939 @samp{E} to indicate the exponent.\n\ |
3372 | 3940 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3941 @item free\n\ |
3372 | 3942 @itemx none\n\ |
3943 Print output in free format, without trying to line up columns of\n\ | |
3944 matrices on the decimal point. This also causes complex numbers to be\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3945 formatted as numeric pairs like this @samp{(0.60419, 0.60709)} instead\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3946 of like this @samp{0.60419 + 0.60709i}.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3947 @end table\n\ |
529 | 3948 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3949 The following formats affect all numeric output (floating point and\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3950 integer types).\n\ |
3372 | 3951 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3952 @table @code\n\ |
19231
ec10705dbd83
doc: note that command form "format + abc" requires quotes around the "+".
Carnë Draug <carandraug@octave.org>
parents:
18849
diff
changeset
|
3953 @item \"+\"\n\ |
ec10705dbd83
doc: note that command form "format + abc" requires quotes around the "+".
Carnë Draug <carandraug@octave.org>
parents:
18849
diff
changeset
|
3954 @itemx \"+\" @var{chars}\n\ |
4632 | 3955 @itemx plus\n\ |
3956 @itemx plus @var{chars}\n\ | |
19232
97eea1e2d9ff
pr-output.cc: fix default chars for "format +" for Matlab compatibility
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
3957 Print a @samp{+} symbol for matrix elements greater than zero, a\n\ |
97eea1e2d9ff
pr-output.cc: fix default chars for "format +" for Matlab compatibility
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
3958 @samp{-} symbol for elements less than zero and a space for zero matrix\n\ |
97eea1e2d9ff
pr-output.cc: fix default chars for "format +" for Matlab compatibility
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
3959 elements. This format can be very useful for examining the structure\n\ |
97eea1e2d9ff
pr-output.cc: fix default chars for "format +" for Matlab compatibility
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
3960 of a large sparse matrix.\n\ |
3372 | 3961 \n\ |
4632 | 3962 The optional argument @var{chars} specifies a list of 3 characters to use\n\ |
3963 for printing values greater than zero, less than zero and equal to zero.\n\ | |
19405
cbce5d1bcaf9
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19368
diff
changeset
|
3964 For example, with the @samp{\"+\" \"+-.\"} format,\n\ |
cbce5d1bcaf9
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19368
diff
changeset
|
3965 @code{[1, 0, -1; -1, 0, 1]} is displayed as\n\ |
4632 | 3966 \n\ |
3967 @example\n\ | |
3968 @group\n\ | |
3969 ans =\n\ | |
3970 \n\ | |
3971 +.-\n\ | |
3972 -.+\n\ | |
3973 @end group\n\ | |
3974 @end example\n\ | |
3975 \n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3976 @item bank\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3977 Print in a fixed format with two digits to the right of the decimal\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3978 point.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3979 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3980 @item native-hex\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3981 Print the hexadecimal representation of numbers as they are stored in\n\ |
3372 | 3982 memory. For example, on a workstation which stores 8 byte real values\n\ |
3983 in IEEE format with the least significant byte first, the value of\n\ | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
3984 @code{pi} when printed in @code{native-hex} format is\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
3985 @code{400921fb54442d18}.\n\ |
3372 | 3986 \n\ |
4833 | 3987 @item hex\n\ |
3988 The same as @code{native-hex}, but always print the most significant\n\ | |
3989 byte first.\n\ | |
10840 | 3990 \n\ |
4833 | 3991 @item native-bit\n\ |
3372 | 3992 Print the bit representation of numbers as stored in memory.\n\ |
3993 For example, the value of @code{pi} is\n\ | |
3994 \n\ | |
3995 @example\n\ | |
3996 @group\n\ | |
3997 01000000000010010010000111111011\n\ | |
3998 01010100010001000010110100011000\n\ | |
3999 @end group\n\ | |
4000 @end example\n\ | |
4001 \n\ | |
4002 (shown here in two 32 bit sections for typesetting purposes) when\n\ | |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
4003 printed in native-bit format on a workstation which stores 8 byte real\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
4004 values in IEEE format with the least significant byte first.\n\ |
10840 | 4005 \n\ |
4833 | 4006 @item bit\n\ |
4007 The same as @code{native-bit}, but always print the most significant\n\ | |
4008 bits first.\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4009 \n\ |
6788 | 4010 @item rat\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4011 Print a rational approximation, i.e., values are approximated\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4012 as the ratio of small integers.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4013 For example, with the @samp{rat} format,\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4014 @code{pi} is displayed as @code{355/113}.\n\ |
3372 | 4015 @end table\n\ |
4016 \n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4017 The following two options affect the display of all matrices.\n\ |
3372 | 4018 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4019 @table @code\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4020 @item compact\n\ |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
4021 Remove blank lines around column number labels and between\n\ |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
4022 matrices producing more compact output with more data per page.\n\ |
10840 | 4023 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4024 @item loose\n\ |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
4025 Insert blank lines above and below column number labels and between matrices\n\ |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
4026 to produce a more readable output with less data per page. (default).\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
4027 @end table\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4028 @seealso{fixed_point_format, output_max_field_width, output_precision, split_long_rows, print_empty_dimensions, rats}\n\ |
11547 | 4029 @end deftypefn") |
529 | 4030 { |
1755 | 4031 int argc = args.length () + 1; |
4032 | |
1968 | 4033 string_vector argv = args.make_argv ("format"); |
1755 | 4034 |
529 | 4035 set_format_style (argc, argv); |
4036 | |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
4037 return ovl (); |
529 | 4038 } |
4039 | |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4040 DEFUN (__compactformat__, args, nargout, |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4041 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4042 @deftypefn {} {@var{val} =} __compactformat__ ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4043 @deftypefnx {} {} __compactformat__ (@var{TRUE|FALSE})\n\ |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4044 Undocumented internal function\n\ |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4045 @end deftypefn") |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4046 { |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4047 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
|
4048 } |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4049 |
18801
307a67b04253
pr-output.cc: Clean up unused parameter compilation warning.
Rik <rik@octave.org>
parents:
18735
diff
changeset
|
4050 DEFUN (__formatstring__, , , |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4051 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4052 @deftypefn {} {@var{val} =} __formatstring__ ()\n\ |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4053 Undocumented internal function\n\ |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4054 @end deftypefn") |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4055 { |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4056 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
|
4057 } |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4058 |
5794 | 4059 DEFUN (fixed_point_format, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4060 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4061 @deftypefn {} {@var{val} =} fixed_point_format ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4062 @deftypefnx {} {@var{old_val} =} fixed_point_format (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4063 @deftypefnx {} {} fixed_point_format (@var{new_val}, \"local\")\n\ |
5794 | 4064 Query or set the internal variable that controls whether Octave will\n\ |
18433
812162c34a93
Improve docstring for fixed_point_format().
Rik <rik@octave.org>
parents:
17871
diff
changeset
|
4065 use a scaled format to print matrix values.\n\ |
812162c34a93
Improve docstring for fixed_point_format().
Rik <rik@octave.org>
parents:
17871
diff
changeset
|
4066 \n\ |
812162c34a93
Improve docstring for fixed_point_format().
Rik <rik@octave.org>
parents:
17871
diff
changeset
|
4067 The scaled format prints a scaling factor on the first line of output chosen\n\ |
812162c34a93
Improve docstring for fixed_point_format().
Rik <rik@octave.org>
parents:
17871
diff
changeset
|
4068 such that the largest matrix element can be written with a single leading\n\ |
812162c34a93
Improve docstring for fixed_point_format().
Rik <rik@octave.org>
parents:
17871
diff
changeset
|
4069 digit. For example:\n\ |
3321 | 4070 \n\ |
4071 @example\n\ | |
4072 @group\n\ | |
18433
812162c34a93
Improve docstring for fixed_point_format().
Rik <rik@octave.org>
parents:
17871
diff
changeset
|
4073 logspace (1, 7, 5)'\n\ |
3321 | 4074 ans =\n\ |
4075 \n\ | |
4076 1.0e+07 *\n\ | |
4077 \n\ | |
4078 0.00000\n\ | |
4079 0.00003\n\ | |
4080 0.00100\n\ | |
4081 0.03162\n\ | |
4082 1.00000\n\ | |
4083 @end group\n\ | |
4084 @end example\n\ | |
4085 \n\ | |
4086 @noindent\n\ | |
18433
812162c34a93
Improve docstring for fixed_point_format().
Rik <rik@octave.org>
parents:
17871
diff
changeset
|
4087 Notice that the first value appears to be 0 when it is actually 1. Because\n\ |
18816
e275d15c27b5
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
18815
diff
changeset
|
4088 of the possibility for confusion you should be careful about enabling\n\ |
18433
812162c34a93
Improve docstring for fixed_point_format().
Rik <rik@octave.org>
parents:
17871
diff
changeset
|
4089 @code{fixed_point_format}.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4090 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4091 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4092 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4093 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4094 @seealso{format, output_max_field_width, output_precision}\n\ |
5794 | 4095 @end deftypefn") |
4096 { | |
4097 return SET_INTERNAL_VARIABLE (fixed_point_format); | |
4098 } | |
4099 | |
4100 DEFUN (print_empty_dimensions, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4101 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4102 @deftypefn {} {@var{val} =} print_empty_dimensions ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4103 @deftypefnx {} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4104 @deftypefnx {} {} print_empty_dimensions (@var{new_val}, \"local\")\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4105 Query or set the internal variable that controls whether the dimensions of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4106 empty matrices are printed along with the empty matrix symbol, @samp{[]}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4107 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4108 For example, the expression\n\ |
3321 | 4109 \n\ |
4110 @example\n\ | |
4111 zeros (3, 0)\n\ | |
4112 @end example\n\ | |
4113 \n\ | |
4114 @noindent\n\ | |
4115 will print\n\ | |
4116 \n\ | |
4117 @example\n\ | |
4118 ans = [](3x0)\n\ | |
4119 @end example\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4120 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4121 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4122 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4123 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4124 @seealso{format}\n\ |
5794 | 4125 @end deftypefn") |
4126 { | |
4127 return SET_INTERNAL_VARIABLE (print_empty_dimensions); | |
4128 } | |
4129 | |
4130 DEFUN (split_long_rows, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4131 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4132 @deftypefn {} {@var{val} =} split_long_rows ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4133 @deftypefnx {} {@var{old_val} =} split_long_rows (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4134 @deftypefnx {} {} split_long_rows (@var{new_val}, \"local\")\n\ |
5794 | 4135 Query or set the internal variable that controls whether rows of a matrix\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4136 may be split when displayed to a terminal window.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4137 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4138 If the rows are split, Octave will display the matrix in a series of smaller\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4139 pieces, each of which can fit within the limits of your terminal width and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4140 each set of rows is labeled so that you can easily see which columns are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4141 currently being displayed. For example:\n\ |
3321 | 4142 \n\ |
6670 | 4143 @example\n\ |
3321 | 4144 @group\n\ |
4145 octave:13> rand (2,10)\n\ | |
4146 ans =\n\ | |
4147 \n\ | |
4148 Columns 1 through 6:\n\ | |
4149 \n\ | |
4150 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\ | |
4151 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\ | |
4152 \n\ | |
4153 Columns 7 through 10:\n\ | |
4154 \n\ | |
4155 0.90174 0.11854 0.72313 0.73326\n\ | |
4156 0.44672 0.94303 0.56564 0.82150\n\ | |
4157 @end group\n\ | |
6670 | 4158 @end example\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4159 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4160 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4161 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4162 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4163 @seealso{format}\n\ |
5794 | 4164 @end deftypefn") |
4165 { | |
4166 return SET_INTERNAL_VARIABLE (split_long_rows); | |
4167 } | |
4168 | |
4169 DEFUN (output_max_field_width, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4170 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4171 @deftypefn {} {@var{val} =} output_max_field_width ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4172 @deftypefnx {} {@var{old_val} =} output_max_field_width (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4173 @deftypefnx {} {} output_max_field_width (@var{new_val}, \"local\")\n\ |
5794 | 4174 Query or set the internal variable that specifies the maximum width\n\ |
4175 of a numeric output field.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4176 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4177 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4178 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4179 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4180 @seealso{format, fixed_point_format, output_precision}\n\ |
5794 | 4181 @end deftypefn") |
4182 { | |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
4183 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
|
4184 std::numeric_limits<int>::max ()); |
5794 | 4185 } |
4186 | |
4187 DEFUN (output_precision, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4188 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4189 @deftypefn {} {@var{val} =} output_precision ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4190 @deftypefnx {} {@var{old_val} =} output_precision (@var{new_val})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
4191 @deftypefnx {} {} output_precision (@var{new_val}, \"local\")\n\ |
5794 | 4192 Query or set the internal variable that specifies the minimum number of\n\ |
4193 significant figures to display for numeric output.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4194 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4195 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4196 variable is changed locally for the function and any subroutines it calls.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4197 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4198 @seealso{format, fixed_point_format, output_max_field_width}\n\ |
5794 | 4199 @end deftypefn") |
4200 { | |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
4201 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
|
4202 std::numeric_limits<int>::max ()); |
5794 | 4203 } |