Mercurial > hg > octave-nkf
annotate scripts/miscellaneous/cast.m @ 18432:2e62b1f01bfe stable
* mkoctfile.in.cc: Use std:: instead of using declarartion.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 24 Jan 2014 04:19:00 -0500 |
parents | d63878346099 |
children | 9b163d6c1de7 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17338
diff
changeset
|
1 ## Copyright (C) 2007-2013 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 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
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 | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
15466
diff
changeset
|
46 |