Mercurial > octave
annotate scripts/strings/dec2base.m @ 31242:96ad887ae4f8 stable
dec2bin.m and dec2hex.m: graft bugfixes from dd6b37f67db2 to stable (bug #63089)
Fix behavior of dec2bin and dec2hex for negative integer-type inputs
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Wed, 28 Sep 2022 17:00:43 -0400 |
parents | 796f54d4ddbf |
children | 5d3faba0342e |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30383
diff
changeset
|
3 ## Copyright (C) 2000-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26986
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
3789 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
3789 | 11 ## 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:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22540
diff
changeset
|
13 ## (at your option) any later version. |
3789 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22540
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22540
diff
changeset
|
18 ## GNU General Public License for more details. |
3789 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## 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:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
3789 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
27 ## @deftypefn {} {} dec2base (@var{d}, @var{base}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
28 ## @deftypefnx {} {} dec2base (@var{d}, @var{base}, @var{len}) |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
29 ## Return a string of symbols in base @var{base} corresponding to the |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
30 ## non-negative integer @var{d}. |
3789 | 31 ## |
32 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
33 ## @group |
3789 | 34 ## dec2base (123, 3) |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
35 ## @result{} "11120" |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
36 ## @end group |
3789 | 37 ## @end example |
38 ## | |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
39 ## If @var{d} is a matrix or cell array, return a string matrix with one row |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
40 ## per element in @var{d}, padded with leading zeros to the width of the |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
41 ## largest value. |
3789 | 42 ## |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11172
diff
changeset
|
43 ## If @var{base} is a string then the characters of @var{base} are used as |
29198
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
44 ## the symbols for the digits of @var{d}. Whitespace (spaces, tabs, newlines, |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
45 ##, etc.@:) may not be used as a symbol. |
3789 | 46 ## |
47 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
48 ## @group |
3789 | 49 ## dec2base (123, "aei") |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
50 ## @result{} "eeeia" |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
51 ## @end group |
3789 | 52 ## @end example |
4492 | 53 ## |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
54 ## The optional third argument, @var{len}, specifies the minimum number of |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
55 ## digits in the result. |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
11169
diff
changeset
|
56 ## @seealso{base2dec, dec2bin, dec2hex} |
3789 | 57 ## @end deftypefn |
58 | |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
59 function retval = dec2base (d, base, len) |
3789 | 60 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
27985
diff
changeset
|
61 if (nargin < 2) |
6046 | 62 print_usage (); |
3789 | 63 endif |
64 | |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
65 if (iscell (d)) |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
66 d = cell2mat (d); |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
67 endif |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
68 |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
16773
diff
changeset
|
69 ## Create column vector for algorithm |
22540
6574e90e8e27
dec2base.m: avoid check for vectorization, as it is done anyway.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22323
diff
changeset
|
70 d = d(:); |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
71 |
16773
3542e106c496
dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14868
diff
changeset
|
72 ## Treat logical as numeric for compatibility with ML |
3542e106c496
dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14868
diff
changeset
|
73 if (islogical (d)) |
3542e106c496
dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14868
diff
changeset
|
74 d = double (d); |
3542e106c496
dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14868
diff
changeset
|
75 elseif (! isnumeric (d) || iscomplex (d) || any (d < 0 | d != fix (d))) |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
76 error ("dec2base: input must be real non-negative integers"); |
3789 | 77 endif |
78 | |
79 symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
5443 | 80 if (ischar (base)) |
29198
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
81 symbols = base(:).'; # force a row vector |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
82 base = numel (symbols); |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
83 if (numel (unique (symbols)) != base) |
5407 | 84 error ("dec2base: symbols representing digits must be unique"); |
29198
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
85 elseif (any (isspace (symbols))) |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
11169
diff
changeset
|
86 error ("dec2base: whitespace characters are not valid symbols"); |
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
11169
diff
changeset
|
87 endif |
29198
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
88 elseif (! isscalar (base) || ! isreal (base) || fix (base) != base |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
89 || base < 2 || base > 36) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
90 error ("dec2base: BASE must be an integer between 2 and 36, or a string of symbols"); |
3789 | 91 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
92 |
5125 | 93 ## determine number of digits required to handle all numbers, can overflow |
94 ## by 1 digit | |
22540
6574e90e8e27
dec2base.m: avoid check for vectorization, as it is done anyway.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22323
diff
changeset
|
95 max_len = round (log (max (max (d), 1)) / log (base)) + 1; |
4492 | 96 |
97 if (nargin == 3) | |
29198
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
98 if (! (isscalar (len) && isreal (len) && len >= 0 && len == fix (len))) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
99 error ("dec2base: LEN must be a non-negative integer"); |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
100 endif |
4492 | 101 max_len = max (max_len, len); |
102 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
103 |
3789 | 104 ## determine digits for each number |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
105 digits = zeros (length (d), max_len); |
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
106 for k = max_len:-1:1 |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
107 digits(:,k) = mod (d, base); |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
108 d = round ((d - digits(:,k)) / base); |
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
109 endfor |
3789 | 110 |
111 ## convert digits to symbols | |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
112 retval = reshape (symbols(digits+1), size (digits)); |
3789 | 113 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21580
diff
changeset
|
114 ## Check if the first element is the zero symbol. It seems possible |
5133 | 115 ## that LEN is provided, and is less than the computed MAX_LEN and |
116 ## MAX_LEN is computed to be one larger than necessary, so we would | |
117 ## have a leading zero to remove. But if LEN >= MAX_LEN, we should | |
118 ## not remove any leading zeros. | |
119 if ((nargin == 2 || (nargin == 3 && max_len > len)) | |
26986
16d4e3d14213
dec2base.m: Correctly handle zero matrix input (bug #56005).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
120 && columns (retval) != 1 && ! any (retval(:,1) != symbols(1))) |
5125 | 121 retval = retval(:,2:end); |
122 endif | |
123 | |
3789 | 124 endfunction |
5125 | 125 |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
126 |
5125 | 127 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
128 %! s0 = ""; |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
129 %! for n = 1:13 |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
130 %! for b = 2:16 |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
131 %! pp = dec2base (b^n+1, b); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
132 %! assert (dec2base (b^n, b), ['1',s0,'0']); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
133 %! assert (dec2base (b^n+1, b), ['1',s0,'1']); |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
134 %! endfor |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
135 %! s0 = [s0,'0']; |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
136 %! endfor |
5125 | 137 |
138 %!test | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
139 %! digits = "0123456789ABCDEF"; |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
140 %! for n = 1:13 |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
141 %! for b = 2:16 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
142 %! pm = dec2base (b^n-1, b); |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
143 %! assert (length (pm), n); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
144 %! assert (all (pm == digits(b))); |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
145 %! endfor |
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
146 %! endfor |
5125 | 147 |
148 %!test | |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
149 %! for b = 2:16 |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
150 %! assert (dec2base (0, b), '0'); |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
151 %! endfor |
5125 | 152 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
153 %!assert (dec2base (0, 2, 4), "0000") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
154 %!assert (dec2base (2^51-1, 2), ... |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
155 %! "111111111111111111111111111111111111111111111111111") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
156 %!assert (dec2base (uint64 (2)^63-1, 16), "7FFFFFFFFFFFFFFF") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
157 %!assert (dec2base ([1, 2; 3, 4], 2, 3), ["001"; "011"; "010"; "100"]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
158 %!assert (dec2base ({1, 2; 3, 4}, 2, 3), ["001"; "011"; "010"; "100"]) |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
159 |
16773
3542e106c496
dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14868
diff
changeset
|
160 %!test |
3542e106c496
dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14868
diff
changeset
|
161 %! a = 0:3; |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
162 %! assert (dec2base (! a, 2, 1), ["1"; "0"; "0"; "0"]); |
16773
3542e106c496
dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14868
diff
changeset
|
163 |
26986
16d4e3d14213
dec2base.m: Correctly handle zero matrix input (bug #56005).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
164 %!assert <*56005> (dec2base ([0, 0], 16), ["0"; "0"]) |
16d4e3d14213
dec2base.m: Correctly handle zero matrix input (bug #56005).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
165 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
166 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
167 %!error <Invalid call> dec2base () |
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
168 %!error <Invalid call> dec2base (1) |
29198
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
169 %!error <input must be real non-negative integers> dec2base ("A", 10) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
170 %!error <input must be real non-negative integers> dec2base (2i, 10) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
171 %!error <input must be real non-negative integers> dec2base (-1, 10) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
172 %!error <input must be real non-negative integers> dec2base (1.1, 10) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
173 %!error <symbols representing digits must be unique> dec2base (1, "ABA") |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
174 %!error <whitespace characters are not valid symbols> dec2base (1, "A B") |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
175 %!error <BASE must be an integer> dec2base (1, ones (2)) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
176 %!error <BASE must be an integer> dec2base (1, 2i) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
177 %!error <BASE must be an integer> dec2base (1, 2.5) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
178 %!error <BASE must be .* between 2 and 36> dec2base (1, 1) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
179 %!error <BASE must be .* between 2 and 36> dec2base (1, 37) |
30383
8afdeac24ba4
maint: Use space after function name and before opening parenthesis.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
180 %!error <LEN must be a non-negative integer> dec2base (1, 2, ones (2)) |
29198
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
181 %!error <LEN must be a non-negative integer> dec2base (1, 2, 2i) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
182 %!error <LEN must be a non-negative integer> dec2base (1, 2, -1) |
ec33b1617cd5
dec2base.m: Overhaul input validation.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
183 %!error <LEN must be a non-negative integer> dec2base (1, 2, 2.5) |