Next: User-defined Data Types, Up: Data Types [Contents][Index]

### 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.

Function File: classname = class (obj)
Function File: class (s, id)
Function File: 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: typeinfo, isa.

Function File: 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.

  See also: class, typeinfo.

Function File: cast (val, type)

  Convert val to data type type.

  See also: int8, uint8, int16, uint16, int32, uint32, int64, uint64, double.

Built-in Function: 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 reserved for 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 should 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: cast, bitunpack, bitpack, swapbytes.

Function File: 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: typecast, cast.

Built-in Function: y = bitpack (x, class)

  Return a new array y resulting from interpreting an array x as raw bit patterns for data of the numeric class class. class must be one of the built-in numeric classes:

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

  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: bitunpack, typecast.

Built-in Function: y = bitunpack (x)

  Return an array y corresponding to the raw bit patterns of x. x must belong to one of the built-in numeric classes:

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

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

  See also: bitpack, typecast.

Next: User-defined Data Types, Up: Data Types [Contents][Index]