Mercurial > octave
annotate scripts/general/num2str.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 1993-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
5 ## |
2313 | 6 ## |
7 ## This file is part of Octave. | |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
2313 | 10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
12 ## (at your option) any later version. |
2313 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
17 ## GNU General Public License for more details. |
2313 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
245 | 22 |
3361 | 23 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20486
diff
changeset
|
24 ## @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
|
25 ## @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
|
26 ## @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
|
27 ## 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
|
28 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
29 ## 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
|
30 ## 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
|
31 ## 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
|
32 ## @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
|
33 ## |
576daea679fe
num2str.m: Clarify in docstring that leading spaces will be trimmed (bug #38463)
Rik <rik@octave.org>
parents:
15732
diff
changeset
|
34 ## Examples: |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
35 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
36 ## @example |
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) |
26600
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
38 ## @result{} 123.456 |
8442
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 ## num2str (123.456, 4) |
26600
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
41 ## @result{} 123.5 |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
42 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
43 ## s = num2str ([1, 1.34; 3, 3.56], "%5.1f") |
26600
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
44 ## @result{} s = |
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
45 ## 1.0 1.3 |
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
46 ## 3.0 3.6 |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
47 ## whos s |
26600
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
48 ## @result{} Variables in the current scope: |
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
49 ## Attr Name Size Bytes Class |
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
50 ## ==== ==== ==== ===== ===== |
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
51 ## s 2x8 16 char |
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
52 ## Total is 16 elements using 16 bytes |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
53 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
54 ## num2str (1.234 + 27.3i) |
26600
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
55 ## @result{} 1.234+27.3i |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
56 ## @end example |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
57 ## |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
58 ## 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
|
59 ## 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
|
60 ## |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
61 ## 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
|
62 ## |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
63 ## 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
|
64 ## the string. |
576daea679fe
num2str.m: Clarify in docstring that leading spaces will be trimmed (bug #38463)
Rik <rik@octave.org>
parents:
15732
diff
changeset
|
65 ## |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
66 ## 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
|
67 ## |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
68 ## 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
|
69 ## 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
|
70 ## unpredictable. |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
71 ## |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
72 ## 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
|
73 ## 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
|
74 ## @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
|
75 ## @seealso{sprintf, int2str, mat2str} |
3361 | 76 ## @end deftypefn |
4 | 77 |
4229 | 78 function retval = num2str (x, arg) |
4 | 79 |
4878 | 80 if (nargin != 1 && nargin != 2) |
5947 | 81 print_usage (); |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
82 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
|
83 error ("num2str: X must be a numeric, logical, or character array"); |
4878 | 84 endif |
85 | |
5443 | 86 if (ischar (x)) |
4878 | 87 retval = x; |
5947 | 88 elseif (isempty (x)) |
89 retval = ""; | |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
90 elseif (isreal (x)) |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
91 if (nargin == 2) |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
92 if (ischar (arg)) |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
97 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
|
98 endif |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
99 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
100 if (isnumeric (x)) |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
101 ## 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
|
102 valid = isfinite (x(:)); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 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
|
107 |
25603
e55fb9685803
num2str.m: Ensure Matlab compatibility for numbers greater than 1e15 (bug #36133)
Rik <rik@octave.org>
parents:
25602
diff
changeset
|
108 if (ndgt > 15 || 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
|
109 ## Floating point input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
114 ## Integer input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
115 ndgt += 3; |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
116 if (any (! valid)) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
117 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
|
118 endif |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
119 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
|
120 endif |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
121 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
122 ## Logical input |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
123 fmt = "%3d"; |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
124 endif |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
125 endif |
20195
ea5fdb2ae637
num2str.m: Correctly parse newlines in single-quoted format strings (bug #44684).
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 endif |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
133 strtmp = sprintf (fmt, x); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
134 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
|
135 else # Complex matrix input |
4878 | 136 if (nargin == 2) |
5443 | 137 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
|
138 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
|
139 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
|
140 fmt = sprintf ("%%%d.%dg%%-+%d.%dgi", arg+7, arg, arg+7, arg); |
4878 | 141 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
142 error ("num2str: PRECISION must be a scalar integer >= 0"); |
4878 | 143 endif |
144 else | |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
145 ## 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 endif |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
153 |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
154 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
|
155 ## Floating point input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
156 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
|
157 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
|
158 fmt = sprintf ("%%%d.%dg%%-+%d.%dgi", ndgt+7, ndgt, ndgt+7, ndgt); |
4878 | 159 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
160 ## Integer input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
161 ndgt += 3; |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22470
diff
changeset
|
162 ## FIXME: Integers must be masked to show only 16 significant digits |
22470
9d4cb0cf9cd2
maint: tag xtests and tests that fail on some systems with bug numbers
Mike Miller <mtmiller@octave.org>
parents:
22323
diff
changeset
|
163 ## See test case for bug #36133 below |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
164 fmt = sprintf ("%%%d.0f%%-+%d.0fi", ndgt, ndgt); |
4878 | 165 endif |
166 endif | |
167 | |
168 ## Manipulate the complex value to have real values in the odd | |
4914 | 169 ## 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
|
170 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
|
171 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
|
172 idx = repmat ({':'}, nd, 1); |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
173 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
|
174 perm(2:2:2*nc) = nc + (1:nc); |
4914 | 175 idx{2} = perm; |
7208 | 176 x = horzcat (real (x), imag (x)); |
4914 | 177 x = x(idx{:}); |
21076
b433f9990452
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
21057
diff
changeset
|
178 |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
179 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
|
180 tmp = sprintf (fmt, permute (x, [2, 3:nd, 1])); |
4878 | 181 |
182 ## 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
|
183 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
|
184 tmp = regexprep (tmp, "( +)i", "i$1"); |
4878 | 185 |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
186 retval = strtrim (char (ostrsplit (tmp(1:end-1), "\n"))); |
4 | 187 endif |
188 | |
189 endfunction | |
7411 | 190 |
191 | |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
192 ## Basic tests |
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 |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
200 ## Exceptional values |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
201 %!assert (num2str (19440606), "19440606") |
14538
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), "-8589934592") |
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") |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
205 %!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
|
206 %!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
|
207 %!assert (num2str (inf), "Inf") |
17292
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
208 %!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
|
209 %!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
|
210 %!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
|
211 %!assert (num2str (complex(Inf,1)), "Inf+1i") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
212 %!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
|
213 %!assert (num2str (nan), "NaN") |
17292
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
214 %!assert (num2str (complex (NaN, 1)), "NaN+1i") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
215 %!assert (num2str (complex (1, NaN)), "1+NaNi") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
216 %!assert (num2str (NA), "NA") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
217 %!assert (num2str (complex (NA, 1)), "NA+1i") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
218 %!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
|
219 |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
220 ## 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
|
221 %!shared m, x |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
222 %! m = magic (3); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
223 %! 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
|
224 |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
225 ## real case |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
226 %!test <*46770> |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
227 %! y = num2str (x); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
228 %! 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
|
229 %! 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
|
230 %! "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
|
231 %! "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
|
232 |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
233 ## complex case |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
234 %!test <*46770> |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
235 %! 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
|
236 %! y = num2str (x); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
237 %! 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
|
238 %! 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
|
239 %! "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
|
240 %! "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
|
241 |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
242 ## Clear shared variables |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
243 %!shared |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
244 |
25603
e55fb9685803
num2str.m: Ensure Matlab compatibility for numbers greater than 1e15 (bug #36133)
Rik <rik@octave.org>
parents:
25602
diff
changeset
|
245 ## Integers greater than 1e15 should switch to exponential notation |
e55fb9685803
num2str.m: Ensure Matlab compatibility for numbers greater than 1e15 (bug #36133)
Rik <rik@octave.org>
parents:
25602
diff
changeset
|
246 %!assert <*36133> (num2str (1e15), "1000000000000000") |
e55fb9685803
num2str.m: Ensure Matlab compatibility for numbers greater than 1e15 (bug #36133)
Rik <rik@octave.org>
parents:
25602
diff
changeset
|
247 %!assert <*36133> (num2str (1e16), "1e+16") |
25602
8f8d3fef29a8
num2str.m: Update Matlab Compatibility BIST tests (bug #36133).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
248 ## Even exact integers in IEEE notation should use exponential notation |
25603
e55fb9685803
num2str.m: Ensure Matlab compatibility for numbers greater than 1e15 (bug #36133)
Rik <rik@octave.org>
parents:
25602
diff
changeset
|
249 %!assert <*36133> (num2str(2^512), "1.34078079299426e+154") |
25602
8f8d3fef29a8
num2str.m: Update Matlab Compatibility BIST tests (bug #36133).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
250 ## Mixed integer/floating point arrays |
25603
e55fb9685803
num2str.m: Ensure Matlab compatibility for numbers greater than 1e15 (bug #36133)
Rik <rik@octave.org>
parents:
25602
diff
changeset
|
251 %!assert <*36133> (num2str ([2.1, 1e23, pi]), |
e55fb9685803
num2str.m: Ensure Matlab compatibility for numbers greater than 1e15 (bug #36133)
Rik <rik@octave.org>
parents:
25602
diff
changeset
|
252 %! "2.1 9.999999999999999e+22 3.141592653589793") |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
253 |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
254 ## Large integers should not switch sign when printed due to overflow |
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
255 %!assert <*36121> (num2str (2.4e9, 15), "2400000000") |
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
256 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22470
diff
changeset
|
257 ## Test for extra rows generated from newlines in format |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
258 %!assert <*44864> (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
|
259 |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
260 ## Test that string conversion of numeric objects results in characters |
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
261 ## if the numbers are within range for ASCII. |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
262 %!assert <*45174> (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
|
263 |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
264 ## Test input validation |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
265 %!error num2str () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
266 %!error num2str (1, 2, 3) |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
267 %!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
|
268 %!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
|
269 %!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
|
270 %!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
|
271 %!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
|
272 %!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
|
273 %!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
|
274 %!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
|
275 %!error <PRECISION must be a scalar integer .= 0> num2str (1+1i, 1.5) |