annotate scripts/strings/dec2base.m @ 20164:df437a52bcaf stable

doc: Update more docstrings to have one sentence summary as first line. Reviewed miscellaneous, sparse, strings in scripts directory. * scripts/miscellaneous/bzip2.m, scripts/miscellaneous/citation.m, scripts/miscellaneous/compare_versions.m, scripts/miscellaneous/computer.m, scripts/miscellaneous/debug.m, scripts/miscellaneous/dir.m, scripts/miscellaneous/edit.m, scripts/miscellaneous/error_ids.m, scripts/miscellaneous/fileattrib.m, scripts/miscellaneous/fullfile.m, scripts/miscellaneous/genvarname.m, scripts/miscellaneous/gzip.m, scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/news.m, scripts/miscellaneous/open.m, scripts/miscellaneous/parseparams.m, scripts/miscellaneous/recycle.m, scripts/miscellaneous/run.m, scripts/miscellaneous/swapbytes.m, scripts/miscellaneous/tar.m, scripts/miscellaneous/tmpnam.m, scripts/miscellaneous/unpack.m, scripts/miscellaneous/what.m, scripts/sparse/bicg.m, scripts/sparse/bicgstab.m, scripts/sparse/cgs.m, scripts/sparse/colperm.m, scripts/sparse/eigs.m, scripts/sparse/etreeplot.m, scripts/sparse/gmres.m, scripts/sparse/gplot.m, scripts/sparse/ichol.m, scripts/sparse/ilu.m, scripts/sparse/pcg.m, scripts/sparse/pcr.m, scripts/sparse/qmr.m, scripts/sparse/spaugment.m, scripts/sparse/spconvert.m, scripts/sparse/spdiags.m, scripts/sparse/spfun.m, scripts/sparse/spones.m, scripts/sparse/sprandsym.m, scripts/sparse/spstats.m, scripts/sparse/spy.m, scripts/sparse/svds.m, scripts/sparse/treelayout.m, scripts/sparse/treeplot.m, scripts/strings/base2dec.m, scripts/strings/bin2dec.m, scripts/strings/blanks.m, scripts/strings/cstrcat.m, scripts/strings/deblank.m, scripts/strings/dec2base.m, scripts/strings/dec2bin.m, scripts/strings/dec2hex.m, scripts/strings/findstr.m, scripts/strings/hex2dec.m, scripts/strings/index.m, scripts/strings/isletter.m, scripts/strings/isstrprop.m, scripts/strings/mat2str.m, scripts/strings/ostrsplit.m, scripts/strings/regexptranslate.m, scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m, scripts/strings/strchr.m, scripts/strings/strjoin.m, scripts/strings/strjust.m, scripts/strings/strmatch.m, scripts/strings/strsplit.m, scripts/strings/strtok.m, scripts/strings/strtrim.m, scripts/strings/strtrunc.m, scripts/strings/substr.m, scripts/strings/untabify.m, scripts/time/datenum.m: Update more docstrings to have one sentence summary as first line.
author Rik <rik@octave.org>
date Mon, 04 May 2015 14:22:02 -0700
parents 9fc020886ae9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19593
diff changeset
1 ## Copyright (C) 2000-2015 Daniel Calvelo
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
2 ##
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
4 ##
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## your option) any later version.
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
9 ##
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
14 ##
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
18
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11172
diff changeset
20 ## @deftypefn {Function File} {} dec2base (@var{d}, @var{base})
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11172
diff changeset
21 ## @deftypefnx {Function File} {} 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
22 ## 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
23 ## non-negative integer @var{d}.
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
24 ##
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
25 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
26 ## @group
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
27 ## dec2base (123, 3)
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
28 ## @result{} "11120"
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
29 ## @end group
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
30 ## @end example
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
31 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
32 ## 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
33 ## 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
34 ## largest value.
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
35 ##
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11172
diff changeset
36 ## If @var{base} is a string then the characters of @var{base} are used as
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
37 ## the symbols for the digits of @var{d}. Space (' ') may not be used as a
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
38 ## symbol.
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
39 ##
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
40 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
41 ## @group
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
42 ## dec2base (123, "aei")
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
43 ## @result{} "eeeia"
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
44 ## @end group
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
45 ## @end example
4492
819e3c246702 [project @ 2003-08-29 17:09:38 by jwe]
jwe
parents: 4030
diff changeset
46 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
47 ## 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
48 ## digits in the result.
11172
7e8ce65f73cf Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents: 11169
diff changeset
49 ## @seealso{base2dec, dec2bin, dec2hex}
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
50 ## @end deftypefn
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
51
3791
c1c532a0acb2 [project @ 2001-02-09 15:28:23 by jwe]
jwe
parents: 3789
diff changeset
52 ## Author: Daniel Calvelo <dcalvelo@yahoo.com>
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
53 ## Adapted-by: Paul Kienzle <pkienzle@kienzle.powernet.co.uk>
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
54
11169
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
55 function retval = dec2base (d, base, len)
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
56
4492
819e3c246702 [project @ 2003-08-29 17:09:38 by jwe]
jwe
parents: 4030
diff changeset
57 if (nargin < 2 || nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
58 print_usage ();
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
59 endif
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
60
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
61 if (iscell (d))
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
62 d = cell2mat (d);
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
63 endif
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
64
17336
b81b9d079515 Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents: 16773
diff changeset
65 ## Create column vector for algorithm
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
66 if (! iscolumn (d))
11169
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
67 d = d(:);
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
68 endif
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
69
16773
3542e106c496 dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14868
diff changeset
70 ## 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
71 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
72 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
73 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
74 error ("dec2base: input must be real non-negative integers");
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
75 endif
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
76
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
77 symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
5443
ec8c33dcd1bf [project @ 2005-09-08 01:40:57 by jwe]
jwe
parents: 5407
diff changeset
78 if (ischar (base))
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
79 symbols = base;
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
80 base = length (symbols);
11169
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
81 if (length (unique (symbols)) != base)
5407
2911127d0fe7 [project @ 2005-07-08 15:37:30 by jwe]
jwe
parents: 5400
diff changeset
82 error ("dec2base: symbols representing digits must be unique");
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
83 endif
11172
7e8ce65f73cf Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents: 11169
diff changeset
84 if (any (isspace (symbols)))
7e8ce65f73cf Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents: 11169
diff changeset
85 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
86 endif
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3791
diff changeset
87 elseif (! isscalar (base))
5407
2911127d0fe7 [project @ 2005-07-08 15:37:30 by jwe]
jwe
parents: 5400
diff changeset
88 error ("dec2base: cannot convert from several bases at once");
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
89 elseif (base < 2 || base > length (symbols))
11169
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
90 error ("dec2base: BASE must be between 2 and 36, or a string of symbols");
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
91 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
92
5125
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
93 ## determine number of digits required to handle all numbers, can overflow
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
94 ## by 1 digit
13309
1f075333d9e8 dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents: 13167
diff changeset
95 max_len = round (log (max (max (d(:)), 1)) / log (base)) + 1;
4492
819e3c246702 [project @ 2003-08-29 17:09:38 by jwe]
jwe
parents: 4030
diff changeset
96
819e3c246702 [project @ 2003-08-29 17:09:38 by jwe]
jwe
parents: 4030
diff changeset
97 if (nargin == 3)
819e3c246702 [project @ 2003-08-29 17:09:38 by jwe]
jwe
parents: 4030
diff changeset
98 max_len = max (max_len, len);
819e3c246702 [project @ 2003-08-29 17:09:38 by jwe]
jwe
parents: 4030
diff changeset
99 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
100
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
101 ## 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
102 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
103 for k = max_len:-1:1
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
104 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
105 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
106 endfor
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
107
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
108 ## convert digits to symbols
13309
1f075333d9e8 dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents: 13167
diff changeset
109 retval = reshape (symbols(digits+1), size (digits));
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
110
5133
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 5125
diff changeset
111 ## Check if the first element is the zero symbol. It seems possible
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 5125
diff changeset
112 ## that LEN is provided, and is less than the computed MAX_LEN and
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 5125
diff changeset
113 ## MAX_LEN is computed to be one larger than necessary, so we would
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 5125
diff changeset
114 ## have a leading zero to remove. But if LEN >= MAX_LEN, we should
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 5125
diff changeset
115 ## not remove any leading zeros.
7191f6e086f9 [project @ 2005-02-08 19:17:41 by jwe]
jwe
parents: 5125
diff changeset
116 if ((nargin == 2 || (nargin == 3 && max_len > len))
13309
1f075333d9e8 dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents: 13167
diff changeset
117 && length (retval) != 1 && ! any (retval(:,1) != symbols(1)))
5125
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
118 retval = retval(:,2:end);
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
119 endif
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
120
3789
2a257be5e488 [project @ 2001-02-09 04:12:30 by jwe]
jwe
parents:
diff changeset
121 endfunction
5125
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
122
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
123
5125
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
124 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
125 %! s0 = "";
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
126 %! for n = 1:13
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
127 %! for b = 2:16
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
128 %! 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
129 %! 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
130 %! 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
131 %! endfor
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
132 %! s0 = [s0,'0'];
13309
1f075333d9e8 dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents: 13167
diff changeset
133 %! endfor
5125
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
134
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
135 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
136 %! digits = "0123456789ABCDEF";
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
137 %! for n = 1:13
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
138 %! 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
139 %! pm = dec2base (b^n-1, b);
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
140 %! 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
141 %! assert (all (pm == digits(b)));
13309
1f075333d9e8 dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents: 13167
diff changeset
142 %! endfor
1f075333d9e8 dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents: 13167
diff changeset
143 %! endfor
5125
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
144
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
145 %!test
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
146 %! for b = 2:16
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
147 %! assert (dec2base (0, b), '0');
13309
1f075333d9e8 dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents: 13167
diff changeset
148 %! endfor
5125
8bf86c0fad1b [project @ 2005-01-27 17:50:57 by jwe]
jwe
parents: 4492
diff changeset
149
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
150 %!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
151 %!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
152 %! "111111111111111111111111111111111111111111111111111")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
153 %!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
154 %!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
155 %!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
156
16773
3542e106c496 dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14868
diff changeset
157 %!test
3542e106c496 dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14868
diff changeset
158 %! a = 0:3;
3542e106c496 dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14868
diff changeset
159 %! assert (dec2base (!a, 2, 1), ["1"; "0"; "0"; "0"])
3542e106c496 dec2base.m: treat logical as double for compatibility with ML (bug #38815).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 14868
diff changeset
160
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
161 ## Test input validation
11169
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
162 %!error dec2base ()
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
163 %!error dec2base (1)
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
164 %!error dec2base (1, 2, 3, 4)
13167
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
165 %!error dec2base ("A")
f7cb824dc8c0 Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
166 %!error dec2base (2i)
11169
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
167 %!error dec2base (-1)
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
168 %!error dec2base (1.1)
13309
1f075333d9e8 dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents: 13167
diff changeset
169 %!error dec2base (1, "ABA")
1f075333d9e8 dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents: 13167
diff changeset
170 %!error dec2base (1, "A B")
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
171 %!error dec2base (1, ones (2))
11169
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
172 %!error dec2base (1, 1)
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
173 %!error dec2base (1, 37)
51beeeff9027 Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents: 9844
diff changeset
174