Mercurial > octave
annotate scripts/general/num2str.m @ 21562:6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
* make_int.cc, file-editor-tab.h, file-editor.cc, shortcut-manager.h,
__contourc__.cc, cellfun.cc, debug.cc, errwarn.h, graphics.in.h, jit-ir.h,
oct-stream.cc, quadcc.cc, qz.cc, sparse-xdiv.cc, symtab.cc, __init_fltk__.cc,
ov-class.cc, ov-float.h, ov-scalar.h, op-int.h, CNDArray.cc, CSparse.cc,
MSparse.cc, Sparse.cc, boolNDArray.cc, chNDArray.cc, dNDArray.cc, dSparse.cc,
fCNDArray.cc, fNDArray.cc, int16NDArray.cc, int32NDArray.cc, int64NDArray.cc,
int8NDArray.cc, intNDArray.cc, uint16NDArray.cc, uint32NDArray.cc,
uint64NDArray.cc, uint8NDArray.cc, randgamma.h, randmtzig.h, randpoisson.c,
randpoisson.h, Sparse-op-defs.h, oct-time.cc, kpse.cc, lo-array-errwarn.h,
lo-ieee.h, del2.m, num2str.m, __isequal__.m, lookfor.m, hsv2rgb.m,
colorspace_conversion_revert.m, fminbnd.m, create_pkgadddel.m, shading.m,
struct2hdl.m, gallery.m, discrete_cdf.m, kolmogorov_smirnov_test.m, assert.m,
datestr.m, classes.tst, jit.tst:
Eliminate accidental double spaces in code.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 30 Mar 2016 15:19:12 -0700 |
parents | a4faec57f4c8 |
children | bac0d6f07a3e |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 1993-2015 John W. Eaton |
2313 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
245 | 18 |
3361 | 19 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20486
diff
changeset
|
20 ## @deftypefn {} {} num2str (@var{x}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20486
diff
changeset
|
21 ## @deftypefnx {} {} num2str (@var{x}, @var{precision}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20486
diff
changeset
|
22 ## @deftypefnx {} {} num2str (@var{x}, @var{format}) |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
23 ## Convert a number (or array) to a string (or a character array). |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
24 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
25 ## The optional second argument may either give the number of significant |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
26 ## digits (@var{precision}) to be used in the output or a format template |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
27 ## string (@var{format}) as in @code{sprintf} (@pxref{Formatted Output}). |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
28 ## @code{num2str} can also process complex numbers. |
16197
576daea679fe
num2str.m: Clarify in docstring that leading spaces will be trimmed (bug #38463)
Rik <rik@octave.org>
parents:
15732
diff
changeset
|
29 ## |
576daea679fe
num2str.m: Clarify in docstring that leading spaces will be trimmed (bug #38463)
Rik <rik@octave.org>
parents:
15732
diff
changeset
|
30 ## Examples: |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
31 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
32 ## @example |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
33 ## @group |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
34 ## num2str (123.456) |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
35 ## @result{} "123.46" |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
36 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
37 ## num2str (123.456, 4) |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
38 ## @result{} "123.5" |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
39 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
40 ## s = num2str ([1, 1.34; 3, 3.56], "%5.1f") |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
41 ## @result{} s = |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
42 ## 1.0 1.3 |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
43 ## 3.0 3.6 |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
44 ## whos s |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
45 ## @result{} |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
46 ## Attr Name Size Bytes Class |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
47 ## ==== ==== ==== ===== ===== |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
48 ## s 2x8 16 char |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
49 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
50 ## num2str (1.234 + 27.3i) |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
51 ## @result{} "1.234+27.3i" |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
52 ## @end group |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
53 ## @end example |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
54 ## |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
55 ## The @code{num2str} function is not very flexible. For better control |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
56 ## over the results, use @code{sprintf} (@pxref{Formatted Output}). |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
57 ## |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
58 ## Programming Notes: |
16197
576daea679fe
num2str.m: Clarify in docstring that leading spaces will be trimmed (bug #38463)
Rik <rik@octave.org>
parents:
15732
diff
changeset
|
59 ## |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
60 ## For @sc{matlab} compatibility, leading spaces are stripped before returning |
16197
576daea679fe
num2str.m: Clarify in docstring that leading spaces will be trimmed (bug #38463)
Rik <rik@octave.org>
parents:
15732
diff
changeset
|
61 ## the string. |
576daea679fe
num2str.m: Clarify in docstring that leading spaces will be trimmed (bug #38463)
Rik <rik@octave.org>
parents:
15732
diff
changeset
|
62 ## |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
63 ## Integers larger than @code{flintmax} may not be displayed correctly. |
16197
576daea679fe
num2str.m: Clarify in docstring that leading spaces will be trimmed (bug #38463)
Rik <rik@octave.org>
parents:
15732
diff
changeset
|
64 ## |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
65 ## For complex @var{x}, the format string may only contain one output |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
66 ## conversion specification and nothing else. Otherwise, results will be |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
67 ## unpredictable. |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
68 ## |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
69 ## Any optional @var{format} specified by the programmer is used without |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
70 ## modification. This is in contrast to @sc{matlab} which tampers with the |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
71 ## @var{format} based on internal heuristics. |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
72 ## @seealso{sprintf, int2str, mat2str} |
3361 | 73 ## @end deftypefn |
4 | 74 |
2314 | 75 ## Author: jwe |
76 | |
4229 | 77 function retval = num2str (x, arg) |
4 | 78 |
4878 | 79 if (nargin != 1 && nargin != 2) |
5947 | 80 print_usage (); |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
81 elseif (! (isnumeric (x) || islogical (x) || ischar (x))) |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
82 error ("num2str: X must be a numeric, logical, or character array"); |
4878 | 83 endif |
84 | |
5443 | 85 if (ischar (x)) |
4878 | 86 retval = x; |
5947 | 87 elseif (isempty (x)) |
88 retval = ""; | |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
89 elseif (isreal (x)) |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
90 if (nargin == 2) |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
91 if (ischar (arg)) |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
92 fmt = arg; |
19725
5f2c0ca0ef51
Ensure that numbers passed to integer *printf format codes are integers (bug #44245).
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
93 elseif (isnumeric (arg) && isscalar (arg) && arg >= 0 && arg == fix (arg)) |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
94 fmt = sprintf ("%%%d.%dg", arg+7, arg); |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
95 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
96 error ("num2str: PRECISION must be a scalar integer >= 0"); |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
97 endif |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
98 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
99 if (isnumeric (x)) |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
100 ## Set up a suitable format string while ignoring Inf/NaN entries |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
101 valid = isfinite (x(:)); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
102 ndgt = floor (log10 (max (abs (x(valid))))); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
103 if (isempty (ndgt) || ndgt == -Inf) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
104 ndgt = 0; # All Inf or all zero array |
15732
82b0ad43a939
num2str: Take into account inf inputs. Add tests for inf and NaN
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14538
diff
changeset
|
105 endif |
82b0ad43a939
num2str: Take into account inf inputs. Add tests for inf and NaN
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14538
diff
changeset
|
106 |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
107 if (any (x(valid) != fix (x(valid)))) |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
108 ## Floating point input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
109 ndgt = max (ndgt + 5, 5); # Keep at least 5 significant digits |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
110 ndgt = min (ndgt, 16); # Cap significant digits at 16 |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
111 fmt = sprintf ("%%%d.%dg", ndgt+7, ndgt); |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
112 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
113 ## Integer input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
114 ndgt += 3; |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
115 if (any (! valid)) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
116 ndgt = max (ndgt, 5); # Allow space for Inf/NaN |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
117 endif |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
118 ## FIXME: Integers should be masked to show only 16 significant digits |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
119 ## See %!xtest with 1e23 below. |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
120 fmt = sprintf ("%%%d.0f", ndgt); |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
121 endif |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
122 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
123 ## Logical input |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
124 fmt = "%3d"; |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
125 endif |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
126 endif |
20195
ea5fdb2ae637
num2str.m: Correctly parse newlines in single-quoted format strings (bug #44684).
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
127 fmt = do_string_escapes (fmt); # required now that '\n' is interpreted. |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
128 nd = ndims (x); |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
129 nc = columns (x) * (nd - 1); # ND-arrays are expanded in columns |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
130 x = permute (x, [2, 3:nd, 1]); |
20266
f357e076776f
num2str.m: Fixed two Matlab compatibility issues (bug #45174, bug #44864).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
20195
diff
changeset
|
131 if (! (sum (fmt == "%") > 1 || any (strcmp (fmt, {"%s", "%c"})))) |
f357e076776f
num2str.m: Fixed two Matlab compatibility issues (bug #45174, bug #44864).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
20195
diff
changeset
|
132 fmt = [deblank(repmat (fmt, 1, nc)), "\n"]; |
f357e076776f
num2str.m: Fixed two Matlab compatibility issues (bug #45174, bug #44864).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
20195
diff
changeset
|
133 endif |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
134 strtmp = sprintf (fmt, x); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
135 retval = strtrim (char (ostrsplit (strtmp, "\n", true))); |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
136 else # Complex matrix input |
4878 | 137 if (nargin == 2) |
5443 | 138 if (ischar (arg)) |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
139 fmt = [deblank(arg) "%-+" arg(2:end) "i"]; |
19725
5f2c0ca0ef51
Ensure that numbers passed to integer *printf format codes are integers (bug #44245).
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
140 elseif (isnumeric (arg) && isscalar (arg) && arg >= 0 && arg == fix (arg)) |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
141 fmt = sprintf ("%%%d.%dg%%-+%d.%dgi", arg+7, arg, arg+7, arg); |
4878 | 142 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
143 error ("num2str: PRECISION must be a scalar integer >= 0"); |
4878 | 144 endif |
145 else | |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
146 ## Set up a suitable format string while ignoring Inf/NaN entries |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
147 valid_real = isfinite (real (x(:))); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
148 valid_imag = isfinite (imag (x(:))); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
149 ndgt = floor (log10 (max (max (abs (real (x(valid_real)))), |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
150 max (abs (imag (x(valid_imag))))))); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
151 if (isempty (ndgt) || ndgt == -Inf) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
152 ndgt = 0; # All Inf or all zero array |
17292
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
153 endif |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
154 |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
155 if (any (x(valid_real & valid_imag) != fix (x(valid_real & valid_imag)))) |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
156 ## Floating point input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
157 ndgt = max (ndgt + 5, 5); # Keep at least 5 significant digits |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
158 ndgt = min (ndgt, 16); # Cap significant digits at 16 |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
159 fmt = sprintf ("%%%d.%dg%%-+%d.%dgi", ndgt+7, ndgt, ndgt+7, ndgt); |
4878 | 160 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
161 ## Integer input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
162 ndgt += 3; |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
163 ## FIXME: Integers should be masked to show only 16 significant digits |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
164 ## See %!xtest below |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
165 fmt = sprintf ("%%%d.0f%%-+%d.0fi", ndgt, ndgt); |
4878 | 166 endif |
167 endif | |
168 | |
169 ## Manipulate the complex value to have real values in the odd | |
4914 | 170 ## columns and imaginary values in the even columns. |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
171 nd = ndims (x); |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
172 nc = columns (x); |
12676
2783fa95cab7
Use common code idiom for creating cell array for indexing ND-arrays
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
173 idx = repmat ({':'}, nd, 1); |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
174 perm(1:2:2*nc) = 1:nc; |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
175 perm(2:2:2*nc) = nc + (1:nc); |
4914 | 176 idx{2} = perm; |
7208 | 177 x = horzcat (real (x), imag (x)); |
4914 | 178 x = x(idx{:}); |
21076
b433f9990452
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
21057
diff
changeset
|
179 |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
180 fmt = [deblank(repmat(fmt, 1, nc * (nd - 1))), "\n"]; |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
181 tmp = sprintf (fmt, permute (x, [2, 3:nd, 1])); |
4878 | 182 |
183 ## Put the "i"'s where they are supposed to be. | |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
184 tmp = regexprep (tmp, " +i\n", "i\n"); |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
185 tmp = regexprep (tmp, "( +)i", "i$1"); |
4878 | 186 |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
187 retval = strtrim (char (ostrsplit (tmp(1:end-1), "\n"))); |
4 | 188 endif |
189 | |
190 endfunction | |
7411 | 191 |
192 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
193 %!assert (num2str (123), "123") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
194 %!assert (num2str (1.23), "1.23") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
195 %!assert (num2str (123.456, 4), "123.5") |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21317
diff
changeset
|
196 %!assert (num2str ([1, 1.34; 3, 3.56], "%5.1f"), ["1.0 1.3"; "3.0 3.6"]) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
197 %!assert (num2str (1.234 + 27.3i), "1.234+27.3i") |
21317
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
21076
diff
changeset
|
198 %!assert (num2str ([true false true]), "1 0 1") |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
199 |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
200 %!assert (num2str (19440606), "19440606") |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
201 %!assert (num2str (2^33), "8589934592") |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
202 %!assert (num2str (-2^33), "-8589934592") |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
203 %!assert (num2str (2^33+1i), "8589934592+1i") |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
204 %!assert (num2str (-2^33+1i), "-8589934592+1i") |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
205 %!assert (num2str ([0 0 0]), "0 0 0") |
15732
82b0ad43a939
num2str: Take into account inf inputs. Add tests for inf and NaN
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14538
diff
changeset
|
206 %!assert (num2str (inf), "Inf") |
17292
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
207 %!assert (num2str ([inf -inf]), "Inf -Inf") |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
208 %!assert (num2str ([inf NaN -inf]), "Inf NaN -Inf") |
17292
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
209 %!assert (num2str ([complex(Inf,0), complex(0,-Inf)]), "Inf+0i 0-Infi") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
210 %!assert (num2str (complex(Inf,1)), "Inf+1i") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
211 %!assert (num2str (complex(1,Inf)), "1+Infi") |
15732
82b0ad43a939
num2str: Take into account inf inputs. Add tests for inf and NaN
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14538
diff
changeset
|
212 %!assert (num2str (nan), "NaN") |
17292
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
213 %!assert (num2str (complex (NaN, 1)), "NaN+1i") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
214 %!assert (num2str (complex (1, NaN)), "1+NaNi") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
215 %!assert (num2str (NA), "NA") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
216 %!assert (num2str (complex (NA, 1)), "NA+1i") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
217 %!assert (num2str (complex (1, NA)), "1+NAi") |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
218 |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
219 ## ND-arrays are concatenated in columns |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
220 %!shared m, x |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
221 %! m = magic (3); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
222 %! x = cat (3, m, -m); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
223 |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
224 ## real case |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
225 %!test |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
226 %! y = num2str (x); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
227 %! assert (rows (y) == 3); |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
228 %! assert (y, ["8 1 6 -8 -1 -6" |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
229 %! "3 5 7 -3 -5 -7" |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
230 %! "4 9 2 -4 -9 -2"]); |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
231 |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
232 ## complex case |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
233 %!test |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
234 %! x(1,1,2) = -8+2i; |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
235 %! y = num2str (x); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
236 %! assert (rows (y) == 3); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
237 %! assert (y, ["8+0i 1+0i 6+0i -8+2i -1+0i -6+0i" |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
238 %! "3+0i 5+0i 7+0i -3+0i -5+0i -7+0i" |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
239 %! "4+0i 9+0i 2+0i -4+0i -9+0i -2+0i"]); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
240 |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
241 ## Clear shared variables |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
242 %!shared |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
243 |
20486 | 244 ## FIXME: Integers greater than flintmax() - 1 should be masked to show just |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
245 ## 16 digits of precision. |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
246 %!xtest |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
247 %! assert (num2str (1e23), "100000000000000000000000"); |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
248 |
20195
ea5fdb2ae637
num2str.m: Correctly parse newlines in single-quoted format strings (bug #44684).
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
249 ## Test for bug #44864, extra rows generated from newlines in format |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
250 %!assert (rows (num2str (magic (3), "%3d %3d %3d\n")), 3) |
20195
ea5fdb2ae637
num2str.m: Correctly parse newlines in single-quoted format strings (bug #44684).
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
251 |
20266
f357e076776f
num2str.m: Fixed two Matlab compatibility issues (bug #45174, bug #44864).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
20195
diff
changeset
|
252 ## Test for bug #45174 |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
253 %!assert (num2str ([65 66 67], "%s"), "ABC") |
20266
f357e076776f
num2str.m: Fixed two Matlab compatibility issues (bug #45174, bug #44864).
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents:
20195
diff
changeset
|
254 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
255 %!error num2str () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
256 %!error num2str (1, 2, 3) |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
257 %!error <X must be a numeric> num2str ({1}) |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
258 %!error <PRECISION must be a scalar integer .= 0> num2str (1, {1}) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
259 %!error <PRECISION must be a scalar integer .= 0> num2str (1, ones (2)) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
260 %!error <PRECISION must be a scalar integer .= 0> num2str (1, -1) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
261 %!error <PRECISION must be a scalar integer .= 0> num2str (1, 1.5) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
262 %!error <PRECISION must be a scalar integer .= 0> num2str (1+1i, {1}) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
263 %!error <PRECISION must be a scalar integer .= 0> num2str (1+1i, ones (2)) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
264 %!error <PRECISION must be a scalar integer .= 0> num2str (1+1i, -1) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
265 %!error <PRECISION must be a scalar integer .= 0> num2str (1+1i, 1.5) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
266 |