Mercurial > octave
annotate scripts/general/num2str.m @ 27898:4d6d21839dfd
remove Author: jwe and Adapted-by: jwe lines from source files
These lines have little meaning now in the age of modern version
control systems.
Files affected: url-transfer.cc, url-transfer.h, acot.m, acoth.m,
acsc.m, acsch.m, asec.m, asech.m, cot.m, coth.m, csc.m, csch.m, sec.m,
sech.m, cart2pol.m, cart2sph.m, deal.m, fliplr.m, flipud.m, int2str.m,
logspace.m, num2str.m, pol2cart.m, rot90.m, sortrows.m, sph2cart.m,
waitbar.m, doc.m, hsv2rgb.m, rgb2hsv.m, beep.m, isstr.m, setstr.m,
strmatch.m, cond.m, rank.m, trace.m, bug_report.m, cast.m, delete.m,
dir.m, list_primes.m, ls.m, ls_command.m, menu.m, pack.m, recycle.m,
substruct.m, version.m, glpk.m, axis.m, box.m, grid.m,
__axis_label__.m, text.m, title.m, view.m, xlabel.m, ylabel.m,
zlabel.m, bar.m, barh.m, comet3.m, hist.m, line.m, loglog.m, mesh.m,
patch.m, plot.m, polar.m, __bar__.m, __line__.m, __plt__.m,
__stem__.m, semilogx.m, semilogy.m, sombrero.m, stairs.m, stem.m,
surface.m, __default_plot_options__.m, __gnuplot_drawnow__.m,
__next_line_color__.m, __plt_get_axis_arg__.m, __pltopt__.m, clf.m,
closereq.m, gca.m, gnuplot_binary.in.m, isfigure.m, meshgrid.m,
__gnuplot_draw_axes__.m, __gnuplot_draw_figure__.m, shg.m, addpref.m,
getpref.m, ispref.m, loadprefs.m, prefsfile.m, saveprefs.m, rmpref.m,
setpref.m, ismember.m, setdiff.m, union.m, hankel.m, hilb.m, vander.m,
median.m, std.m, cstrcat.m, isletter.m, str2num.m, strcat.m,
oruntests.m, rundemos.m, asctime.m, clock.m, ctime.m, date.m, etime.m,
is_leap_year.m.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 02 Jan 2020 15:43:01 -0500 |
parents | 45ad2127582b |
children | b442ec6dda5c |
rev | line source |
---|---|
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25654
diff
changeset
|
1 ## Copyright (C) 1993-2019 John W. Eaton |
2313 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
5 ## Octave is free software: you can redistribute it and/or modify it |
2313 | 6 ## 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
|
7 ## 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
|
8 ## (at 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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
13 ## GNU General Public License for more details. |
2313 | 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 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
17 ## <https://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 ## 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
|
34 ## @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
|
35 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
36 ## 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
|
37 ## @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
|
38 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
39 ## 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
|
40 ## @result{} s = |
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
41 ## 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
|
42 ## 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
|
43 ## whos s |
26600
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
44 ## @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
|
45 ## 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
|
46 ## ==== ==== ==== ===== ===== |
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
47 ## 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
|
48 ## 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
|
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) |
26600
f6730533820e
doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents:
26376
diff
changeset
|
51 ## @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
|
52 ## @end example |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7540
diff
changeset
|
53 ## |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
54 ## 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
|
55 ## 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
|
56 ## |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
57 ## 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
|
58 ## |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
59 ## 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
|
60 ## the string. |
576daea679fe
num2str.m: Clarify in docstring that leading spaces will be trimmed (bug #38463)
Rik <rik@octave.org>
parents:
15732
diff
changeset
|
61 ## |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
62 ## 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
|
63 ## |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
64 ## 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
|
65 ## 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
|
66 ## unpredictable. |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
67 ## |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
68 ## 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
|
69 ## 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
|
70 ## @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
|
71 ## @seealso{sprintf, int2str, mat2str} |
3361 | 72 ## @end deftypefn |
4 | 73 |
4229 | 74 function retval = num2str (x, arg) |
4 | 75 |
4878 | 76 if (nargin != 1 && nargin != 2) |
5947 | 77 print_usage (); |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
78 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
|
79 error ("num2str: X must be a numeric, logical, or character array"); |
4878 | 80 endif |
81 | |
5443 | 82 if (ischar (x)) |
4878 | 83 retval = x; |
5947 | 84 elseif (isempty (x)) |
85 retval = ""; | |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
86 elseif (isreal (x)) |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
87 if (nargin == 2) |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
88 if (ischar (arg)) |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
93 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
|
94 endif |
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 if (isnumeric (x)) |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
97 ## 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
|
98 valid = isfinite (x(:)); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 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
|
103 |
25603
e55fb9685803
num2str.m: Ensure Matlab compatibility for numbers greater than 1e15 (bug #36133)
Rik <rik@octave.org>
parents:
25602
diff
changeset
|
104 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
|
105 ## Floating point input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
110 ## Integer input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
111 ndgt += 3; |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
112 if (any (! valid)) |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
113 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
|
114 endif |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
115 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
|
116 endif |
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
117 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
118 ## Logical input |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
119 fmt = "%3d"; |
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 endif |
20195
ea5fdb2ae637
num2str.m: Correctly parse newlines in single-quoted format strings (bug #44684).
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 endif |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
129 strtmp = sprintf (fmt, x); |
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
130 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
|
131 else # Complex matrix input |
4878 | 132 if (nargin == 2) |
5443 | 133 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
|
134 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
|
135 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
|
136 fmt = sprintf ("%%%d.%dg%%-+%d.%dgi", arg+7, arg, arg+7, arg); |
4878 | 137 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
138 error ("num2str: PRECISION must be a scalar integer >= 0"); |
4878 | 139 endif |
140 else | |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
141 ## 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 endif |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
149 |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
150 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
|
151 ## Floating point input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
152 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
|
153 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
|
154 fmt = sprintf ("%%%d.%dg%%-+%d.%dgi", ndgt+7, ndgt, ndgt+7, ndgt); |
4878 | 155 else |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
156 ## Integer input |
21057
b0afe1993268
Overhaul num2str.m and int2str.m for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
21003
diff
changeset
|
157 ndgt += 3; |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22470
diff
changeset
|
158 ## 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
|
159 ## 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
|
160 fmt = sprintf ("%%%d.0f%%-+%d.0fi", ndgt, ndgt); |
4878 | 161 endif |
162 endif | |
163 | |
164 ## Manipulate the complex value to have real values in the odd | |
4914 | 165 ## 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
|
166 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
|
167 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
|
168 idx = repmat ({':'}, nd, 1); |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
169 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
|
170 perm(2:2:2*nc) = nc + (1:nc); |
4914 | 171 idx{2} = perm; |
7208 | 172 x = horzcat (real (x), imag (x)); |
4914 | 173 x = x(idx{:}); |
21076
b433f9990452
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
21057
diff
changeset
|
174 |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
175 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
|
176 tmp = sprintf (fmt, permute (x, [2, 3:nd, 1])); |
4878 | 177 |
178 ## 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
|
179 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
|
180 tmp = regexprep (tmp, "( +)i", "i$1"); |
4878 | 181 |
16724
b7667fcb9fbc
Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents:
16403
diff
changeset
|
182 retval = strtrim (char (ostrsplit (tmp(1:end-1), "\n"))); |
4 | 183 endif |
184 | |
185 endfunction | |
7411 | 186 |
187 | |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
188 ## Basic tests |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
189 %!assert (num2str (123), "123") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
190 %!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
|
191 %!assert (num2str (123.456, 4), "123.5") |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21317
diff
changeset
|
192 %!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
|
193 %!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
|
194 %!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
|
195 |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
196 ## Exceptional values |
14537
f8e041f11b18
num2str.m: Update function to address bug #36117 and bug #36121.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
197 %!assert (num2str (19440606), "19440606") |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
198 %!assert (num2str (2^33), "8589934592") |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
199 %!assert (num2str (-2^33), "-8589934592") |
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
200 %!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
|
201 %!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
|
202 %!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
|
203 %!assert (num2str (inf), "Inf") |
17292
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
204 %!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
|
205 %!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
|
206 %!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
|
207 %!assert (num2str (complex(Inf,1)), "Inf+1i") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
208 %!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
|
209 %!assert (num2str (nan), "NaN") |
17292
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
210 %!assert (num2str (complex (NaN, 1)), "NaN+1i") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
211 %!assert (num2str (complex (1, NaN)), "1+NaNi") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
212 %!assert (num2str (NA), "NA") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
213 %!assert (num2str (complex (NA, 1)), "NA+1i") |
c5073ed27cdc
Handle '+' format modifier in sprintf (bug #39773)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
214 %!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
|
215 |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
216 ## 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
|
217 %!shared m, x |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
218 %! m = magic (3); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
219 %! 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
|
220 |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
221 ## real case |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
222 %!test <*46770> |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
223 %! y = num2str (x); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
224 %! 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
|
225 %! 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
|
226 %! "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
|
227 %! "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
|
228 |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
229 ## complex case |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
230 %!test <*46770> |
21003
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
231 %! 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
|
232 %! y = num2str (x); |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
233 %! 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
|
234 %! 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
|
235 %! "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
|
236 %! "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
|
237 |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
238 ## Clear shared variables |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
239 %!shared |
b51078f07886
num2str.m: Expand ND-arrays in columns for Matlab compatibility (bug #46770).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
240 |
25603
e55fb9685803
num2str.m: Ensure Matlab compatibility for numbers greater than 1e15 (bug #36133)
Rik <rik@octave.org>
parents:
25602
diff
changeset
|
241 ## 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
|
242 %!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
|
243 %!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
|
244 ## 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
|
245 %!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
|
246 ## 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
|
247 %!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
|
248 %! "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
|
249 |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
250 ## 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
|
251 %!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
|
252 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22470
diff
changeset
|
253 ## 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
|
254 %!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
|
255 |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
256 ## 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
|
257 ## 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
|
258 %!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
|
259 |
25654
6541a0de38e1
num2str.m: Add new BIST tests and comments explaining tests.
Rik <rik@octave.org>
parents:
25603
diff
changeset
|
260 ## Test input validation |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
261 %!error num2str () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
262 %!error num2str (1, 2, 3) |
14538
34c932e669c8
num2str.m: Redraft code for better Matlab compatibility.
Rik <octave@nomad.inbox5.com>
parents:
14537
diff
changeset
|
263 %!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
|
264 %!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
|
265 %!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
|
266 %!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
|
267 %!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
|
268 %!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
|
269 %!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
|
270 %!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
|
271 %!error <PRECISION must be a scalar integer .= 0> num2str (1+1i, 1.5) |