[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: casting
From: |
John W. Eaton |
Subject: |
Re: casting |
Date: |
Tue, 13 Mar 2007 10:45:34 -0400 |
On 13-Mar-2007, Søren Hauberg wrote:
| Just a few stupid questions :-)
| Is feval really so slow that you switch-case is faster?
No, feval should be is approximately the same as calling a function.
But a series of switch cases is probably slightly faster than a series
of calls to strcmp. You are right that using strcmp with a cell array
is probably faster than a series of switch cases. I just forgot that
strcmp could be used this way. So I changed the function to
function retval = cast (val, typ)
if (nargin == 2)
if (ischar (typ))
if (any (strcmp (typ, {"int8"; "uint8"; "int16"; "uint16";
"int32"; "uint32"; "int64"; "uint64";
"double"; "single"})))
retval = feval (typ, val);
else
error ("cast: type name `%s' is not a built-in type", typ);
endif
else
error ("cast: expecting type name as second argument");
endif
else
print_usage ();
endif
endfunction
| Also, I that you handle the "single" type in your code. Does octave
| support "single" now?
Not really, but there is a single function that converts to double.
It's not completely correct, but doing that allows some code that
requires single to run.
Thanks,
jwe
- casting, David Grohmann, 2007/03/09