Double-precision arrays
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;
whos x
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
10308.
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
+
or sin
.
If you have an array of a different data type, such as single
or
int8
, then you can convert that array to double precision using
the double
function, which then stores the array with more precision
for further computations.
When you are creating a class, overload double
when it
makes sense to convert an object of that class to a double-precision
value.