Mercurial > hg > octave-nkf
annotate scripts/strings/dec2base.m @ 14363:f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
* wavread.m, acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m,
asec.m, asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m,
csc.m, cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, accumarray.m,
accumdim.m, bitcmp.m, bitget.m, bitset.m, blkdiag.m, cart2pol.m, cart2sph.m,
celldisp.m, chop.m, circshift.m, colon.m, common_size.m, cplxpair.m,
cumtrapz.m, curl.m, dblquad.m, deal.m, divergence.m, flipdim.m, fliplr.m,
flipud.m, genvarname.m, gradient.m, idivide.m, int2str.m, interp1.m,
interp1q.m, interp2.m, interp3.m, interpft.m, interpn.m, isa.m, isdir.m,
isequal.m, isequalwithequalnans.m, issquare.m, logspace.m, nargchk.m,
narginchk.m, nargoutchk.m, nextpow2.m, nthargout.m, num2str.m, pol2cart.m,
polyarea.m, postpad.m, prepad.m, profile.m, profshow.m, quadgk.m, quadv.m,
randi.m, rat.m, repmat.m, rot90.m, rotdim.m, shift.m, shiftdim.m, sph2cart.m,
structfun.m, trapz.m, triplequad.m, convhull.m, dsearch.m, dsearchn.m,
griddata3.m, griddatan.m, rectint.m, tsearchn.m, __makeinfo__.m, doc.m,
get_first_help_sentence.m, help.m, type.m, unimplemented.m, which.m, imread.m,
imwrite.m, dlmwrite.m, fileread.m, is_valid_file_id.m, strread.m, textread.m,
textscan.m, commutation_matrix.m, cond.m, condest.m, cross.m,
duplication_matrix.m, expm.m, housh.m, isdefinite.m, ishermitian.m,
issymmetric.m, logm.m, normest.m, null.m, onenormest.m, orth.m, planerot.m,
qzhess.m, rank.m, rref.m, trace.m, vech.m, ans.m, bincoeff.m, bug_report.m,
bzip2.m, comma.m, compare_versions.m, computer.m, edit.m, fileparts.m,
fullfile.m, getfield.m, gzip.m, info.m, inputname.m, isappdata.m, isdeployed.m,
ismac.m, ispc.m, isunix.m, list_primes.m, ls.m, mexext.m, namelengthmax.m,
news.m, orderfields.m, paren.m, recycle.m, rmappdata.m, semicolon.m,
setappdata.m, setfield.m, substruct.m, symvar.m, ver.m, version.m,
warning_ids.m, xor.m, fminbnd.m, fsolve.m, fzero.m, lsqnonneg.m, optimset.m,
pqpnonneg.m, sqp.m, matlabroot.m, __gnuplot_drawnow__.m,
__plt_get_axis_arg__.m, ancestor.m, cla.m, clf.m, close.m, colorbar.m,
colstyle.m, comet3.m, contourc.m, figure.m, gca.m, gcbf.m, gcbo.m, gcf.m,
ginput.m, graphics_toolkit.m, gtext.m, hggroup.m, hist.m, hold.m, isfigure.m,
ishghandle.m, ishold.m, isocolors.m, isonormals.m, isosurface.m, isprop.m,
legend.m, line.m, loglog.m, loglogerr.m, meshgrid.m, ndgrid.m, newplot.m,
orient.m, patch.m, plot3.m, plotyy.m, __print_parse_opts__.m, quiver3.m,
refreshdata.m, ribbon.m, semilogx.m, semilogxerr.m, semilogy.m, stem.m,
stem3.m, subplot.m, title.m, uigetfile.m, view.m, whitebg.m, compan.m, conv.m,
deconv.m, mkpp.m, mpoles.m, pchip.m, poly.m, polyaffine.m, polyder.m,
polyfit.m, polygcd.m, polyint.m, polyout.m, polyval.m, polyvalm.m, ppder.m,
ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, intersect.m,
ismember.m, powerset.m, setdiff.m, setxor.m, union.m, unique.m,
autoreg_matrix.m, bartlett.m, blackman.m, detrend.m, fftconv.m, fftfilt.m,
fftshift.m, freqz.m, hamming.m, hanning.m, ifftshift.m, sinc.m, sinetone.m,
sinewave.m, unwrap.m, bicg.m, bicgstab.m, gmres.m, gplot.m, nonzeros.m, pcg.m,
pcr.m, spaugment.m, spconvert.m, spdiags.m, speye.m, spfun.m, spones.m,
sprand.m, sprandsym.m, spstats.m, spy.m, svds.m, treelayout.m, bessel.m,
beta.m, betaln.m, factor.m, factorial.m, isprime.m, lcm.m, legendre.m,
nchoosek.m, nthroot.m, perms.m, pow2.m, primes.m, reallog.m, realpow.m,
realsqrt.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, rosser.m,
vander.m, __finish__.m, center.m, cloglog.m, corr.m, cov.m, gls.m, histc.m,
iqr.m, kendall.m, kurtosis.m, logit.m, mahalanobis.m, mean.m, meansq.m,
median.m, mode.m, moment.m, ols.m, ppplot.m, prctile.m, probit.m, quantile.m,
range.m, ranks.m, run_count.m, runlength.m, skewness.m, spearman.m,
statistics.m, std.m, table.m, var.m, zscore.m, betacdf.m, betainv.m, betapdf.m,
betarnd.m, binocdf.m, binoinv.m, binopdf.m, binornd.m, cauchy_cdf.m,
cauchy_inv.m, cauchy_pdf.m, cauchy_rnd.m, chi2cdf.m, chi2inv.m, chi2pdf.m,
chi2rnd.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, discrete_rnd.m,
empirical_cdf.m, empirical_inv.m, empirical_pdf.m, empirical_rnd.m, expcdf.m,
expinv.m, exppdf.m, exprnd.m, fcdf.m, finv.m, fpdf.m, frnd.m, gamcdf.m,
gaminv.m, gampdf.m, gamrnd.m, geocdf.m, geoinv.m, geopdf.m, geornd.m,
hygecdf.m, hygeinv.m, hygepdf.m, hygernd.m, kolmogorov_smirnov_cdf.m,
laplace_cdf.m, laplace_inv.m, laplace_pdf.m, laplace_rnd.m, logistic_cdf.m,
logistic_inv.m, logistic_pdf.m, logistic_rnd.m, logncdf.m, logninv.m,
lognpdf.m, lognrnd.m, nbincdf.m, nbininv.m, nbinpdf.m, nbinrnd.m, normcdf.m,
norminv.m, normpdf.m, normrnd.m, poisscdf.m, poissinv.m, poisspdf.m,
poissrnd.m, stdnormal_cdf.m, stdnormal_inv.m, stdnormal_pdf.m, stdnormal_rnd.m,
tcdf.m, tinv.m, tpdf.m, trnd.m, unidcdf.m, unidinv.m, unidpdf.m, unidrnd.m,
unifcdf.m, unifinv.m, unifpdf.m, unifrnd.m, wblcdf.m, wblinv.m, wblpdf.m,
wblrnd.m, kolmogorov_smirnov_test.m, kruskal_wallis_test.m, base2dec.m,
bin2dec.m, blanks.m, cstrcat.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m,
findstr.m, hex2dec.m, index.m, isletter.m, mat2str.m, rindex.m, str2num.m,
strcat.m, strjust.m, strmatch.m, strsplit.m, strtok.m, strtrim.m, strtrunc.m,
substr.m, validatestring.m, demo.m, example.m, fail.m, speed.m, addtodate.m,
asctime.m, clock.m, ctime.m, date.m, datenum.m, datetick.m, datevec.m,
eomday.m, etime.m, is_leap_year.m, now.m:
Use Octave coding conventions in all m-file %!test blocks
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 13 Feb 2012 07:29:44 -0800 |
parents | 4d917a6a858b |
children | 5d3a684236b0 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13309
diff
changeset
|
1 ## Copyright (C) 2000-2012 Daniel Calvelo |
3789 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3789 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3789 | 18 |
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}) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11172
diff
changeset
|
22 ## Return a string of symbols in base @var{base} corresponding to |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
23 ## the non-negative integer @var{d}. |
3789 | 24 ## |
25 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## @group |
3789 | 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 | 30 ## @end example |
31 ## | |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
32 ## If @var{d} is a matrix or cell array, return a string matrix with one |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
33 ## row per element in @var{d}, padded with leading zeros to the width of |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
34 ## the largest value. |
3789 | 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 |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
37 ## the symbols for the digits of @var{d}. Space (' ') may not be used |
3789 | 38 ## as a symbol. |
39 ## | |
40 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
41 ## @group |
3789 | 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 | 45 ## @end example |
4492 | 46 ## |
47 ## The optional third argument, @var{len}, specifies the minimum | |
48 ## number of 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 | 50 ## @end deftypefn |
51 | |
3791 | 52 ## Author: Daniel Calvelo <dcalvelo@yahoo.com> |
3789 | 53 ## Adapted-by: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
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 | 56 |
4492 | 57 if (nargin < 2 || nargin > 3) |
6046 | 58 print_usage (); |
3789 | 59 endif |
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 |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
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 |
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
69 |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
70 if (! isnumeric (d) || iscomplex (d) || any (d < 0 | d != fix (d))) |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
71 error ("dec2base: input must be real non-negative integers"); |
3789 | 72 endif |
73 | |
74 symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
5443 | 75 if (ischar (base)) |
3789 | 76 symbols = base; |
77 base = length (symbols); | |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
78 if (length (unique (symbols)) != base) |
5407 | 79 error ("dec2base: symbols representing digits must be unique"); |
3789 | 80 endif |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
11169
diff
changeset
|
81 if (any (isspace (symbols))) |
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
11169
diff
changeset
|
82 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
|
83 endif |
4030 | 84 elseif (! isscalar (base)) |
5407 | 85 error ("dec2base: cannot convert from several bases at once"); |
3789 | 86 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
|
87 error ("dec2base: BASE must be between 2 and 36, or a string of symbols"); |
3789 | 88 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
89 |
5125 | 90 ## determine number of digits required to handle all numbers, can overflow |
91 ## by 1 digit | |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
92 max_len = round (log (max (max (d(:)), 1)) / log (base)) + 1; |
4492 | 93 |
94 if (nargin == 3) | |
95 max_len = max (max_len, len); | |
96 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
97 |
3789 | 98 ## 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
|
99 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
|
100 for k = max_len:-1:1 |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
101 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
|
102 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
|
103 endfor |
3789 | 104 |
105 ## convert digits to symbols | |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
106 retval = reshape (symbols(digits+1), size (digits)); |
3789 | 107 |
5133 | 108 ## Check if the first element is the zero symbol. It seems possible |
109 ## that LEN is provided, and is less than the computed MAX_LEN and | |
110 ## MAX_LEN is computed to be one larger than necessary, so we would | |
111 ## have a leading zero to remove. But if LEN >= MAX_LEN, we should | |
112 ## not remove any leading zeros. | |
113 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
|
114 && length (retval) != 1 && ! any (retval(:,1) != symbols(1))) |
5125 | 115 retval = retval(:,2:end); |
116 endif | |
117 | |
3789 | 118 endfunction |
5125 | 119 |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
120 |
5125 | 121 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
122 %! s0 = ""; |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
123 %! for n = 1:13 |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
124 %! for b = 2:16 |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
125 %! 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
|
126 %! 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
|
127 %! 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
|
128 %! endfor |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
129 %! s0 = [s0,'0']; |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
130 %! endfor |
5125 | 131 |
132 %!test | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
133 %! digits = "0123456789ABCDEF"; |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
134 %! for n = 1:13 |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
135 %! 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
|
136 %! pm = dec2base (b^n-1, b); |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
137 %! 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
|
138 %! assert (all (pm == digits(b))); |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
139 %! endfor |
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
140 %! endfor |
5125 | 141 |
142 %!test | |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
143 %! for b = 2:16 |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
144 %! assert (dec2base (0, b), '0'); |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
145 %! endfor |
5125 | 146 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
147 %!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
|
148 %!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
|
149 %! "111111111111111111111111111111111111111111111111111") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
150 %!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
|
151 %!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
|
152 %!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
|
153 |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
11169
diff
changeset
|
154 %%Test input validation |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
155 %!error dec2base () |
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
156 %!error dec2base (1) |
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
157 %!error dec2base (1, 2, 3, 4) |
13167
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
158 %!error dec2base ("A") |
f7cb824dc8c0
Allow cellstr inputs for dec2* conversion functions.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
159 %!error dec2base (2i) |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
160 %!error dec2base (-1) |
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
161 %!error dec2base (1.1) |
13309
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
162 %!error dec2base (1, "ABA") |
1f075333d9e8
dec2base.m: Code tweaks for slightly better performance.
Rik <octave@nomad.inbox5.com>
parents:
13167
diff
changeset
|
163 %!error dec2base (1, "A B") |
11169
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
164 %!error dec2base (1, ones(2)) |
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
165 %!error dec2base (1, 1) |
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
166 %!error dec2base (1, 37) |
51beeeff9027
Update dec2base to handle numbers up to 2^64-1.
Rik <octave@nomad.inbox5.com>
parents:
9844
diff
changeset
|
167 |