### 4.4 Integer Data Types ¶

Octave supports integer matrices as an alternative to using double precision. It is possible to use both signed and unsigned integers represented by 8, 16, 32, or 64 bits. It should be noted that most computations require floating point data, meaning that integers will often change type when involved in numeric computations. For this reason integers are most often used to store data, and not for calculations.

In general, most integer matrices are created by casting existing matrices to integers. The following example shows how to cast a matrix into 32-bit integers.

    float = rand (2, 2)
         ⇒  float = 0.37569   0.92982
                    0.11962   0.50876
    integer = int32 (float)
         ⇒  integer = 0  1
                      0  1

As can be seen, floating point values are rounded to the nearest integer when converted.

`tf =` isinteger `(x)` ¶

  Return true if x is an integer object (int8, uint8, int16, etc.).

  Note that `isinteger (14)` is false because numeric constants in Octave are double precision floating point values.

  See also: isfloat, ischar, islogical, isstring, isnumeric, isa.

`y =` int8 `(x)` ¶

  Convert x to 8-bit integer type.

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

`y =` uint8 `(x)` ¶

  Convert x to unsigned 8-bit integer type.

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

`y =` int16 `(x)` ¶

  Convert x to 16-bit integer type.

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

`y =` uint16 `(x)` ¶

  Convert x to unsigned 16-bit integer type.

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

`y =` int32 `(x)` ¶

  Convert x to 32-bit integer type.

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

`y =` uint32 `(x)` ¶

  Convert x to unsigned 32-bit integer type.

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

`y =` int64 `(x)` ¶

  Convert x to 64-bit integer type.

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

`y =` uint64 `(x)` ¶

  Convert x to unsigned 64-bit integer type.

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

`Imax =` intmax `()` ¶
`Imax =` intmax `("type")` ¶
`Imax =` intmax `(var)` ¶

  Return the largest integer that can be represented by a specific integer type.

  The input is either a string `"type"` specifying an integer type, or it is an existing integer variable var.

  Possible values for type are

  `"int8"`

    signed 8-bit integer.

  `"int16"`

    signed 16-bit integer.

  `"int32"`

    signed 32-bit integer.

  `"int64"`

    signed 64-bit integer.

  `"uint8"`

    unsigned 8-bit integer.

  `"uint16"`

    unsigned 16-bit integer.

  `"uint32"`

    unsigned 32-bit integer.

  `"uint64"`

    unsigned 64-bit integer.

  The default for type is `"int32"`.

  Example Code - query an existing variable

      x = int8 (1);
      intmax (x)
        ⇒  127

  See also: intmin, flintmax.

`Imin =` intmin `()` ¶
`Imin =` intmin `("type")` ¶
`Imin =` intmin `(var)` ¶

  Return the smallest integer that can be represented by a specific integer type.

  The input is either a string `"type"` specifying an integer type, or it is an existing integer variable var.

  Possible values for type are

  `"int8"`

    signed 8-bit integer.

  `"int16"`

    signed 16-bit integer.

  `"int32"`

    signed 32-bit integer.

  `"int64"`

    signed 64-bit integer.

  `"uint8"`

    unsigned 8-bit integer.

  `"uint16"`

    unsigned 16-bit integer.

  `"uint32"`

    unsigned 32-bit integer.

  `"uint64"`

    unsigned 64-bit integer.

  The default for type is `"int32"`.

  Example Code - query an existing variable

      x = int8 (1);
      intmin (x)
        ⇒  -128

  See also: intmax, flintmax.

`Imax =` flintmax `()` ¶
`Imax =` flintmax `("double")` ¶
`Imax =` flintmax `("single")` ¶
`Imax =` flintmax `(var)` ¶

  Return the largest integer that can be represented consecutively in a floating point value.

  The input is either a string specifying a floating point type, or it is an existing floating point variable var.

  The default type is `"double"`, but `"single"` is a valid option. On IEEE 754 compatible systems, `flintmax` is 2^{53} for `"double"` and 2^{24} for `"single"`.

  Example Code - query an existing variable

      x = single (1);
      flintmax (x)
        ⇒  16777216

  See also: intmax, realmax, realmin.