Fundamental Data Types − Float, Double & Long double
Today we are going to talk about two fundamental data types called float and
double. We are also going to have a brief introduction to fixed and floating point.
We will also see some coding examples to help you illustrate the concept of float ,
double and long double. These different data types are of different sizes as well.
In my system, float takes 4 bytes of space. Double takes 8 bytes of memory space.
And long double takes 12 bytes. Size of these data types totally depend on the
system we are working on. Floating point representation on the other hand is quite
unnatural way of representing real numbers. Fixed point representation using equal
number of places would be able to represent much larger range of values. Floating
point is called floating point because the decimal point is not fixed. This is the
reason why floating point is preferred over fixed point. This topic is a part of
computer organization and architecture and explaining further details regarding
this topic is out of the scope. In this first line I have declared a variable of
float type and assigned it a value which is famously known as PIE. Value of PIE is
3. 1415926535897932 and so on. It is going on continuously without even repetition
of the digits. To print long double, we need to put format specifier as L and f.
The precision depends on the size of these data types. If you want less precision,
then you can use float or long double. Some applications require precision up to 2
3 or 4 decimal places. Then using float would be a better choice. And long double
up to 19 digits. Up to this point everything is printed correctly but after that
everything is changed. The correct answer is changing these integer values to
fractional values 4. 0 and 9. 0. Placing. 0 after 4 and 9 make these these numbers
double. By default they are double constants. And if you want to make them float
you just have to place f at the suffix. If you try to print this value then it will
give you your desired result which is 0. 44.
Today we are going to talk about two fundamental data types called float and
double. We are also going to have a brief introduction to fixed and floating point.
We will also see some coding examples to help you illustrate the concept of float ,
double and long double. These different data types are of different sizes as well.
In my system, float takes 4 bytes of space. Double takes 8 bytes of memory space.
And long double takes 12 bytes. Size of these data types totally depend on the
system we are working on. Floating point representation on the other hand is quite
unnatural way of representing real numbers. Fixed point representation using equal
number of places would be able to represent much larger range of values. Floating
point is called floating point because the decimal point is not fixed. This is the
reason why floating point is preferred over fixed point. This topic is a part of
computer organization and architecture and explaining further details regarding
this topic is out of the scope. In this first line I have declared a variable of
float type and assigned it a value which is famously known as PIE. Value of PIE is
3. 1415926535897932 and so on. It is going on continuously without even repetition
of the digits. To print long double, we need to put format specifier as L and f.
The precision depends on the size of these data types. If you want less precision,
then you can use float or long double. Some applications require precision up to 2
3 or 4 decimal places. Then using float would be a better choice. And long double
up to 19 digits. Up to this point everything is printed correctly but after that
everything is changed. The correct answer is changing these integer values to
fractional values 4. 0 and 9. 0. Placing. 0 after 4 and 9 make these these numbers
double. By default they are double constants. And if you want to make them float
you just have to place f at the suffix. If you try to print this value then it will
give you your desired result which is 0. 44.