changeset 23134:01bf5c733de7 stable

doc: Expand documentation for cast() (bug #50201). * cast.m: Clarify behavior of cast and add a programming note explaining how it might be used with user-defined classes.
author Rik <rik@octave.org>
date Wed, 01 Feb 2017 21:06:04 -0800
parents 0f2582425a9e
children be2654b2f34f 4e313457b5f9
files scripts/miscellaneous/cast.m
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/cast.m	Wed Feb 01 20:39:51 2017 -0800
+++ b/scripts/miscellaneous/cast.m	Wed Feb 01 21:06:04 2017 -0800
@@ -20,7 +20,8 @@
 ## @deftypefn {} {} cast (@var{val}, "@var{type}")
 ## Convert @var{val} to data type @var{type}.
 ##
-## @var{val} must be one of the numeric classes:
+## Both @var{val} and @var{type} are typically one of the following built-in
+## classes:
 ##
 ## @example
 ## @group
@@ -52,6 +53,18 @@
 ## @end group
 ## @end example
 ##
+## Programming Note: This function relies on the object @var{val} having a
+## conversion method named @var{type}.  User-defined classes may implement only
+## a subset of the full list of types shown above.  In that case, it may be
+## necessary to call cast twice in order to reach the desired type.
+## For example, the conversion to double is nearly always implemented, but
+## the conversion to uint8 might not be.  In that case, the following code will
+## work
+##
+## @example
+## cast (cast (@var{user_defined_val}, "double"), "uint8")
+## @end example
+##
 ## @seealso{typecast, int8, uint8, int16, uint16, int32, uint32, int64, uint64, double, single, logical, char, class, typeinfo}
 ## @end deftypefn