double is the default numeric data type (class) in
MATLAB®, providing sufficient precision for most computational tasks. Numeric
variables are automatically stored as 64-bit (8-byte) double-precision floating-point
values. For example:
x = 10;
Name Size Bytes Class Attributes x 1x1 8 double
MATLAB constructs the
double data type according to
IEEE® Standard 754 for double precision. The range for a negative number of type
double is between -1.79769 x 10308 and
-2.22507 x 10-308, and the range for positive numbers is
between 2.22507 x 10-308 and 1.79769 x
For more information on double- and single-precision floating-point values, see Floating-Point Numbers.
You create a double-precision array automatically when you assign a numeric scalar or
array to a variable, such as
A = [1 2 3; 4 5 6]. The variable
A has type
double. For more information on
creating and combining arrays, see Creating, Concatenating, and Expanding Matrices. In addition, operations on double-precision variables and functions with
double-precision input typically return double-precision values, such as
If you have an array of a different data type, such as
int8, then you can convert that array to double precision using
double function, which then stores the array with more precision
for further computations.
X — Input array
scalar | vector | matrix | multidimensional array
Input array, specified as a scalar, vector, matrix, or multidimensional array.
Create Double-Precision Variable
By default, numbers in MATLAB are of the data type
double. You can use the
class function to verify a variable's type.
x = 100; xtype = class(x)
xtype = 'double'
double function to convert variables that are not double precision to type
y = true
y = logical
ydouble = double(y); ynewtype = class(ydouble)
ynewtype = 'double'
Double-Precision Versus Single-Precision
Compare the ranges of numeric values in double-precision to the ranges for single-precision.
realmax functions to display the minimum and maximum positives values that can be represented in double precision.
doublemin = realmin('double')
doublemin = 2.2251e-308
doublemax = realmax('double')
doublemax = 1.7977e+308
Now display the minimum and maximum positive values that can be represented in single precision. The range of values is smaller compared to double-precision, but requires less memory.
singlemin = realmin('single')
singlemin = single
singlemax = realmax('single')
singlemax = single
eps function returns a measure of how close numbers can be in double-precision versus single-precision. Display the distance from the number 1.0 to the next larger double-precision number.
doubleeps = eps('double')
doubleeps = 2.2204e-16
Now display the distance from 1.0 to the next larger single-precision number. Double-precision values are closer to each other, since you can represent more of them.
singleeps = eps('single')
singleeps = single
When you are creating a class, overload
doublewhen it makes sense to convert an object of that class to a double-precision value.
chararray to a numeric type will produce an array of the corresponding Unicode® code values. Text in strings does not convert in this way. Converting a string that does not represent a single numeric value to
doublewill produce a
NaNresult. For more information, see Unicode and ASCII Values.
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
For string inputs with misplaced commas (commas that are not used as thousands separators), generated code results can differ from MATLAB results.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Introduced before R2006a