Floating points, numbers, floating point types, store approximations of real numbers, which in our
case can be defined as any number that has a decimal point.
And the fractional part, such as 0.333, three or 98.6 or P.
Although it's not possible to represent an arbitrary real number exactly in computer memory, but it's
possible to store an approximation.
So if it seems hard to believe, just think about magic number P, which has infinitely many digits
with free computer memory.
How could you possibly represent infinitely many digits?
As with all types, floating point types take up a infinite amount of memory, which is called the types
precision.
The more precision floating point type has, the more accurate it will be.
Approximation a real number.
C++ offer three levels of precision for approximations.
The first level is plot.
The second double and the three long double.
So these levels mean of course, these are the imaginary levels, but this is the single precision.
We have the double for double precision.
Double precision.
And the next we have the long double for extended precision.
At precision.
So as with integer types, each floating point representation depends on implementation.
The section won't go into detail about floating point tiles, but note that there is substantial nuance
involved in these implementations.
On major desktop operating system.
The float level usually has four bytes of precision.
Here.
Poor bites.
The double and long hair levels usually usually have eight bytes, eight bytes and long double eight
bytes eight bytes.
So most users are 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 double.
For tools who cannot safely ignore the details.
Look at the floating point specifications relevant to your hardware platform.
And let's go to floating point literals.
Floating point Literals.
They are.
Floating point laterals.
Yes.
We are.
And yes.
The floating point literals are double precision by default.
If you need a single position, use an F or uppercase F suffix for extended precision.
Use L or uppercase L as I will show here.
Float A, for example, 0.1 F, double B, for example 0.2 just a 2 to 0.2.
We don't need to add any literal or suffix.
And lastly, long double long double C equals 0.3 L.
As you can see, we used the uppercase L and uppercase F.
Actually, let's change the comment here so you can see the codes.
So.
And you can also use the scientific notation in literals.
Here.
Double.
For example, Planck's.
Banks constant.
The Planck's constant.
The Planck's constant is six point.
626074004 and E -34.
So you might be wondering what is this though?
So no space here are permitted between the significant the base and the suffix, the potential portion
and the E for 34.
So that's why we didn't use any suffixes or like any space or literal to use for separation of these
codes, these values.
So the floating point format specifiers, we have format specifiers for printing the these numbers on
console.
So the format specified for F displays a float with decimal digits.
Whereas here e.
This place the same number in scientific notation.
You can let printf decide which of these to to use with the g format specified which selects the more
compact of E or F for double.
You simply depend on l lowercase l here to describe desired specifiers, so for long double you prepend
an uppercase l.
For example, if you want to want a double with decimal digits, you will specify l l.
F l or l.
G near.
Well in that comment here double.
With.
Decimal digits.
Yes.
And the.
You will test fire l f, l, or l g here with decimal digits, but for a long double you will you will
specify l lone double double eight decimal digits f or long double.
You need to use the uppercase L on the case F and the same uppercase l.
E or.
L Jim.
So let's write an example code for this and start and compile and run the program, which I will show
you how this format specifiers work on tables.
So we have the main command.
Main.
Function here.
So we can freely use this as our code.
So double.
And here, 6.0.
221409e 23 which I will explain all of these codes later after compiling and print f.
For example, Avogadro's number.
Number is.
I will explain all of these quotes, of course.
Here.
L.
E.
I'll have.
LG and New line Mir, then I will give the three three times the same number, but with different format
specifiers and e.
N.
M.
Here and.
Was this court here.
And lastly, let's create the float number each P 9.9..
76.
Here.
Let's print.
Turned f.
Hogwarts.
Platform.
G.
And e.
F.
G.
New line give this use.
This format uses the HP number with different format.
Specifies three times HP, HP, HP and so.
Imprint after.
And let's finally compile this code here.
Clear.
Yes.
Assuming that zip code is compiled.
Use the e a that.
Let's save this code.
Firstly with control.
Save and let's compile it again.
Use this code.
So.
Okay.
Also.
Yes.
So as you can see here, let me.
Okay.
So as you can see here, the first we did the program declares a double here, double called RN.
The format specified for the format specified l.
E.
Gives you a scientific notation of these numbers.
So let's see what this first.
Gave us.
This is the scientific notation which we used as l.
E.
This is scientific notation.
The program gives us.
And the second way did fear.
Gives the decimal representation of this e n number.
As you can see, this gave us the very long decimal representation of this number.
The last one, LG.
Specify for the chooses the scientific notation of these, as you can see here.
This notation gave us almost the same E and number so.
And here we as you know, we created the plot called each p.
This produce similar printf output using the e and F specifiers as you can see here.
But the format specified.
G here.
Format specified.
G here.
Decided to provide the decimal representation of 9.76.
Rather than the scientific notation as a general.
Use the G.
Print floating point types.
The next lecture will be about the character types.
And I'm waiting you in the next lecture.