Mercurial > hg > octave-lyh
annotate scripts/strings/hex2dec.m @ 13061:addfc0ae69c0
Make bicgstab interface more compatible
* bicgstab.m: Add the possibility to pass a function
handle for the coefficient matrix. Also add more tests.
author | Carlo de Falco <kingcrimson@tiscali.it> |
---|---|
date | Sat, 03 Sep 2011 20:06:30 +0200 |
parents | fd0a3ac60b0e |
children | 36afcd6fc45f |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1996-2011 Daniel Calvelo |
2313 | 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. | |
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 | |
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/>. | |
2268 | 18 |
3361 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} hex2dec (@var{s}) | |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
21 ## Return the integer corresponding to the hexadecimal number represented |
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
22 ## by the string @var{s}. For example: |
3426 | 23 ## |
3361 | 24 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## @group |
3361 | 26 ## hex2dec ("12B") |
27 ## @result{} 299 | |
28 ## hex2dec ("12b") | |
29 ## @result{} 299 | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## @end group |
3361 | 31 ## @end example |
3789 | 32 ## |
33 ## If @var{s} is a string matrix, returns a column vector of converted | |
34 ## numbers, one per row of @var{s}. Invalid rows evaluate to NaN. | |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
35 ## @seealso{dec2hex, base2dec, bin2dec} |
3361 | 36 ## @end deftypefn |
2268 | 37 |
3791 | 38 ## Author: Daniel Calvelo <dcalvelo@yahoo.com> |
3789 | 39 ## Adapted-by: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> |
2314 | 40 |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
41 function d = hex2dec (s) |
2268 | 42 |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
43 if (nargin == 1 && ischar (s)) |
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
44 d = base2dec (s, 16); |
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
45 else |
6046 | 46 print_usage (); |
2268 | 47 endif |
48 | |
49 endfunction | |
7411 | 50 |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
51 %!assert(hex2dec ("0000"), 0); |
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
52 %!assert(hex2dec ("1FFFFFFFFFFFFF"), 2^53-1); |
7411 | 53 %!assert(hex2dec ("12b") == 299 && hex2dec ("12B") == 299); |
54 | |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
55 %%Test input validation |
7411 | 56 %!error hex2dec (); |
11172
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
57 %!error hex2dec (1); |
7e8ce65f73cf
Overhaul functions used to convert between number bases.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
58 %!error hex2dec ("1", 2); |
7411 | 59 |