double - Double-precision arrays - MATLAB (original) (raw)

Main Content

Description

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:

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 typedouble 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.

Creation

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 variableA 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 orint8, then you can convert that array to double precision using the double function, which then stores the array with more precision for further computations.

Syntax

Description

Y = double([X](#d126e434092)) converts the values inX to double precision.

example

Input Arguments

expand all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

Data Types: single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string

Examples

collapse all

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)

Use the double function to convert variables that are not double precision to type double.

ydouble = double(y); ynewtype = class(ydouble)

Compare the ranges of numeric values in double-precision to the ranges for single-precision.

Use the realmin and realmax functions to display the minimum and maximum positives values that can be represented in double precision.

doublemin = realmin('double')

doublemax = realmax('double')

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

1.1755e-38

singlemax = realmax('single')

singlemax = single

3.4028e+38

The 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')

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

1.1921e-07

Tips

Extended Capabilities

expand all

Thedouble function fully supports tall arrays. For more information, see Tall Arrays.

Usage notes and limitations:

The double function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced before R2006a