Floating-Point Numbers
In this section...
“Double-Precision Floating Point” on page 4-6
“Single-Precision Floating Point” on page 4-6
“Creating Floating-Point Data” on page 4-6
“Arithmetic Operations on Floating-Point Numbers” on page 4-8
“Largest and Smallest Values for Floating-Point Classes” on page 4-9
“Accuracy of Floating-Point Data” on page 4-10
“Avoiding Common Problems with Floating-Point Arithmetic” on page 4-11
MATLAB represents floating-point numbers in either double-precision or single-precision format. The
default is double precision, but you can make any number single precision with a simple conversion
function.
Double-Precision Floating Point
MATLAB constructs the double-precision (or double) data type according to IEEE
®
Standard 754 for
double precision. Any value stored as a double requires 64 bits, formatted as shown in the table
below:
Bits
Usage
63
Sign (0 = positive, 1 = negative)
62 to 52
Exponent, biased by 1023
51 to 0
Fraction f of the number 1.f
Single-Precision Floating Point
MATLAB constructs the single-precision (or single) data type according to IEEE Standard 754 for
single precision. Any value stored as a single requires 32 bits, formatted as shown in the table
below:
Bits
Usage
31
Sign (0 = positive, 1 = negative)
30 to 23
Exponent, biased by 127
22 to 0
Fraction f of the number 1.f
Because MATLAB stores numbers of type single using 32 bits, they require less memory than
numbers of type double, which use 64 bits. However, because they are stored with fewer bits,
numbers of type single are represented to less precision than numbers of type double.
Creating Floating-Point Data
Use double-precision to store values greater than approximately 3.4 x 10
38
or less than approximately
-3.4 x 10
38
. For numbers that lie between these two limits, you can use either double- or singleprecision, but single requires less memory.
4 Numeric Classes
4-6
Précédent

- 150/1450

Suivant