Mercurial > octave-antonio
annotate scripts/miscellaneous/cast.m @ 11472:1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 09 Jan 2011 21:33:04 -0800 |
parents | 95c3e38098bf |
children | fd0a3ac60b0e |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2007, 2008 John W. Eaton |
6403 | 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. | |
6403 | 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/>. | |
6403 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} cast (@var{val}, @var{type}) | |
21 ## Convert @var{val} to data type @var{type}. | |
22 ## @seealso{int8, uint8, int16, uint16, int32, uint32, int64, uint64, double} | |
23 ## @end deftypefn | |
24 | |
25 ## Author: jwe | |
26 | |
27 function retval = cast (val, typ) | |
28 | |
29 if (nargin == 2) | |
30 if (ischar (typ)) | |
31 if (any (strcmp (typ, {"int8"; "uint8"; "int16"; "uint16"; | |
10549 | 32 "int32"; "uint32"; "int64"; "uint64"; |
33 "double"; "single"; "logical"; "char"}))) | |
34 retval = feval (typ, val); | |
6403 | 35 else |
10549 | 36 error ("cast: type name `%s' is not a built-in type", typ); |
6403 | 37 endif |
38 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
39 error ("cast: expecting TYPE name as second argument"); |
6403 | 40 endif |
41 else | |
42 print_usage (); | |
43 endif | |
44 | |
45 endfunction |