int8

Converts values to signed 8-bit integers, from -128 to 127.

Category: Language Fundamentals > Data Types

Syntax

B = int8(A)

Converts A to class int8.

Description

Fractions are rounded to the nearest integer, with ties going away from zero. Out-of-range values saturate at intmin('int8') or intmax('int8') instead of wrapping around, and NaN becomes 0. Arithmetic between a int8 and a double gives a int8, rounded after the operation; mixing two different integer classes is an error.

The class has no representation for Inf or NaN, so int8(Inf) is intmax('int8').

Input arguments

A
Numeric, logical or char array.

Output arguments

B
Array of class int8, same size as A.

Example

Rounding and saturation

int8(100) + int8(100)
int8(-200)
int8(7.5)
class(int8(3))
int8(NaN)
Output
ans = int8
   127
ans = int8
   -128
ans = int8
   8
ans = 'int8'
ans = int8
   0

See also

intmax intmin double uint8 round cast