This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Convert to 64-bit signed integer


intArray = int64(array)


intArray = int64(array) converts the elements of an array into signed 64-bit (8-byte) integers of class int64.

Input Arguments


Array of any numeric class, such as single or double. If array is already of class int64, the int64 function has no effect.

Output Arguments


Array of class int64. Values range from –263 to 263 – 1.

The int64 function maps any values in array that are outside the limit to the nearest endpoint. For example,

int64(2^63)   % 2^63 = 9223372036854775808


ans =


Convert a literal value to int64:

x = int64(9007199254740993);


Double-precision floating-point numbers have only 52 bits in the mantissa. Therefore, double values cannot represent all integers greater than 253 correctly. Before performing arithmetic operations on values larger than 253 in magnitude, convert the values to 64-bit integers. For example,

x = int64(2^53+1);     % Floating-point arithmetic, loses precision

is not as accurate as the 64-bit integer arithmetic operation:

x = int64(2^53) + 1;   % Preferred


When preallocating integer arrays, specify the class in the call to functions that support a class name input (such as zeros, ones or eye), rather than calling an integer conversion function. For example,

I = int64(zeros(100));     % Creates an intermediate array

is not as efficient as

I = zeros(100, 'int64');   % Preferred 

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a

Was this topic helpful?