C++ Crash Course: a fast-Paced Introduction



Yüklə 7 Mb.
Pdf görüntüsü
səhifə66/71
tarix20.09.2023
ölçüsü7 Mb.
#145939
1   ...   63   64   65   66   67   68   69   70   71
C Crash Course A Fast-Paced Introduction by Josh Lospinoso

Floating-Point Types
Floating-point types store approximations of real numbers (which in our case 
can be defined as any number that has a decimal point and a fractional part, 
such as 0.33333 or 98.6). Although it’s not possible to represent an arbi-
trary real number exactly in computer memory, it’s possible to store an 
approximation. If this seems hard to believe, just think of a number like 
π

which has infinitely many digits. With finite computer memory, how could 
you possibly represent infinitely many digits? 
As with all types, floating-point types take up a finite amount of mem-
ory, which is called the type’s precision. The more precision a floating-point 
type has, the more accurate it will be at approximating a real number. C++ 
offers three levels of precision for approximations:
float
single precision
double
double precision
long double
extended precision
As with integer types, each floating-point representation depends on 
implementation. This section won’t go into detail about floating-point types, 
but note that there is substantial nuance involved in these implementations.
On major desktop operating systems, the 
float
level usually has 4 bytes 
of precision. The 
double
and 
long double
levels usually have 8 bytes of preci-
sion (double precision).
Most users not involved in scientific computing applications can safely 
ignore the details of floating-point representation. In such cases, a good 
general rule is to use a 
double

N O T E
 
For those who cannot safely ignore the details, look at the floating-point specification 
relevant to your hardware platform. The predominant implementation of floating-
point storage and arithmetic is outlined in The IEEE Standard for Floating-
Point Arithmetic, IEEE 754.

Yüklə 7 Mb.

Dostları ilə paylaş:
1   ...   63   64   65   66   67   68   69   70   71




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin