(octave.info)Built-in Data Types


Next: User-defined Data Types Up: Data Types
Enter node , (file) or (file)node

3.1 Built-in Data Types
=======================

The standard built-in data types are real and complex scalars and
matrices, ranges, character strings, a data structure type, and cell
arrays.  Additional built-in data types may be added in future versions.
If you need a specialized data type that is not currently provided as a
built-in type, you are encouraged to write your own user-defined data
type and contribute it for distribution in a future release of Octave.

   The data type of a variable can be determined and changed through the
use of the following functions.

 -- : CLASSNAME = class (OBJ)
 -- : class (S, ID)
 -- : class (S, ID, P, ...)
     Return the class of the object OBJ, or create a class with fields
     from structure S and name (string) ID.

     Additional arguments name a list of parent classes from which the
     new class is derived.

     See also: Note: typeinfo, Note: isa.

 -- : isa (OBJ, CLASSNAME)
     Return true if OBJ is an object from the class CLASSNAME.

     CLASSNAME may also be one of the following class categories:

     "float"
          Floating point value comprising classes "double" and "single".

     "integer"
          Integer value comprising classes (u)int8, (u)int16, (u)int32,
          (u)int64.

     "numeric"
          Numeric value comprising either a floating point or integer
          value.

     If CLASSNAME is a cell array of string, a logical array of the same
     size is returned, containing true for each class to which OBJ
     belongs to.

     See also: Note: class, Note: typeinfo.

 -- : cast (VAL, "TYPE")
     Convert VAL to data type TYPE.

     Both VAL and TYPE are typically one of the following built-in
     classes:

          "double"
          "single"
          "logical"
          "char"
          "int8"
          "int16"
          "int32"
          "int64"
          "uint8"
          "uint16"
          "uint32"
          "uint64"

     The value VAL may be modified to fit within the range of the new
     type.

     Examples:

          cast (-5, "uint8")
             ⇒ 0
          cast (300, "int8")
             ⇒ 127

     Programming Note: This function relies on the object VAL having a
     conversion method named 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

          cast (cast (USER_DEFINED_VAL, "double"), "uint8")

     See also: Note: typecast, Note: int8, Note:
     uint8, Note: int16, Note: uint16,
     Note: int32, Note: uint32, *note int64:
     XREFint64, Note: uint64, Note: double,
     Note: single, Note: logical, *note char:
     XREFchar, Note: class, Note: typeinfo.

 -- : Y = typecast (X, "CLASS")
     Return a new array Y resulting from interpreting the data of X in
     memory as data of the numeric class CLASS.

     Both the class of X and CLASS must be one of the built-in numeric
     classes:

          "logical"
          "char"
          "int8"
          "int16"
          "int32"
          "int64"
          "uint8"
          "uint16"
          "uint32"
          "uint64"
          "double"
          "single"
          "double complex"
          "single complex"

     the last two are only used with CLASS; they indicate that a
     complex-valued result is requested.  Complex arrays are stored in
     memory as consecutive pairs of real numbers.  The sizes of integer
     types are given by their bit counts.  Both logical and char are
     typically one byte wide; however, this is not guaranteed by C++.
     If your system is IEEE conformant, single and double will be 4
     bytes and 8 bytes wide, respectively.  "logical" is not allowed for
     CLASS.

     If the input is a row vector, the return value is a row vector,
     otherwise it is a column vector.

     If the bit length of X is not divisible by that of CLASS, an error
     occurs.

     An example of the use of typecast on a little-endian machine is

          X = uint16 ([1, 65535]);
          typecast (X, "uint8")
          ⇒ [   1,   0, 255, 255]

     See also: Note: cast, Note: bitpack, Note:
     bitunpack, Note: swapbytes.

 -- : swapbytes (X)
     Swap the byte order on values, converting from little endian to big
     endian and vice versa.

     For example:

          swapbytes (uint16 (1:4))
          ⇒ [   256   512   768  1024]

     See also: Note: typecast, Note: cast.

 -- : Y = bitpack (X, CLASS)
     Return a new array Y resulting from interpreting the logical array
     X as raw bit patterns for data of the numeric class CLASS.

     CLASS must be one of the built-in numeric classes:

          "double"
          "single"
          "double complex"
          "single complex"
          "char"
          "int8"
          "int16"
          "int32"
          "int64"
          "uint8"
          "uint16"
          "uint32"
          "uint64"

     The number of elements of X should be divisible by the bit length
     of CLASS.  If it is not, excess bits are discarded.  Bits come in
     increasing order of significance, i.e., ‘x(1)’ is bit 0, ‘x(2)’ is
     bit 1, etc.

     The result is a row vector if X is a row vector, otherwise it is a
     column vector.

     See also: Note: bitunpack, *note typecast:
     XREFtypecast.

 -- : Y = bitunpack (X)
     Return a logical array Y corresponding to the raw bit patterns of
     X.

     X must belong to one of the built-in numeric classes:

          "double"
          "single"
          "char"
          "int8"
          "int16"
          "int32"
          "int64"
          "uint8"
          "uint16"
          "uint32"
          "uint64"

     The result is a row vector if X is a row vector; otherwise, it is a
     column vector.

     See also: Note: bitpack, Note: typecast.

Numeric Objects
Missing Data
String Objects
Data Structure Objects
Cell Array Objects

automatically generated by info2www version 1.2.2.9