octave: Built-in Data Types

 
 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: Seetypeinfo XREFtypeinfo, Seeisa XREFisa.
 
  -- : 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: Seeclass XREFclass, Seetypeinfo XREFtypeinfo.
 
  -- : 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")
 
DONTPRINTYET       See also: Seetypecast XREFtypecast, Seeint8 XREFint8, *noteDONTPRINTYET       See also: Seetypecast XREFtypecast, Seeint8 XREFint8, See
      uint8 XREFuint8, Seeint16 XREFint16, Seeuint16 XREFuint16,
DONTPRINTYET       Seeint32 XREFint32, Seeuint32 XREFuint32, *noteint64:
DONTPRINTYET       Seeint32 XREFint32, Seeuint32 XREFuint32, Seeint64

      XREFint64, Seeuint64 XREFuint64, Seedouble XREFdouble,
DONTPRINTYET       Seesingle XREFsingle, Seelogical XREFlogical, *notechar:
DONTPRINTYET       Seesingle XREFsingle, Seelogical XREFlogical, Seechar

      XREFchar, Seeclass XREFclass, Seetypeinfo XREFtypeinfo.
 
  -- : 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]
 
DONTPRINTYET       See also: Seecast XREFcast, Seebitpack XREFbitpack, *noteDONTPRINTYET       See also: Seecast XREFcast, Seebitpack XREFbitpack, See
      bitunpack XREFbitunpack, Seeswapbytes XREFswapbytes.
 
  -- : 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: Seetypecast XREFtypecast, Seecast XREFcast.
 
  -- : 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.
 
DONTPRINTYET       See also: Seebitunpack XREFbitunpack, *notetypecast:
DONTPRINTYET       See also: Seebitunpack XREFbitunpack, Seetypecast

      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: Seebitpack XREFbitpack, Seetypecast XREFtypecast.
 

Menu