1
00:00:01,080 --> 00:00:03,120
Floating point numbers.

2
00:00:03,450 --> 00:00:05,090
Floating point types.

3
00:00:05,100 --> 00:00:13,740
Store approximations of real numbers, which in our case can be defined as any number that has a decimal

4
00:00:13,740 --> 00:00:21,990
point and a fractional part such as 0.3333 or 98.6 or P.

5
00:00:22,470 --> 00:00:29,160
Although it's not possible to represent an arbitrary real number exactly in computer memory, but it's

6
00:00:29,160 --> 00:00:32,070
possible to store an approximation.

7
00:00:32,070 --> 00:00:41,190
So if it seems hard to believe, just think of it like number P, which has infinitely many digits with

8
00:00:41,190 --> 00:00:43,170
finite computer memory.

9
00:00:43,200 --> 00:00:47,130
How could you possibly represent infinitely many digits?

10
00:00:47,550 --> 00:00:56,520
As with all types, floating point types take up a finite amount of memory, which is called the type's

11
00:00:56,520 --> 00:00:58,140
precision.

12
00:00:58,290 --> 00:01:04,220
The more precision, a floating point type has, the more accurate it will be.

13
00:01:04,240 --> 00:01:05,320
Approximation.

14
00:01:05,350 --> 00:01:08,200
A real number Cplusplus.

15
00:01:08,230 --> 00:01:13,120
Offer three levels of precision for approximations.

16
00:01:13,120 --> 00:01:15,520
The first level is plot.

17
00:01:16,180 --> 00:01:20,260
The second double and a three long double.

18
00:01:20,260 --> 00:01:27,850
So these levels mean, of course, these are the imaginary levels, but this is the single precision.

19
00:01:29,630 --> 00:01:33,680
We have the double for double precision.

20
00:01:34,520 --> 00:01:36,590
Double precision.

21
00:01:36,890 --> 00:01:44,510
And the next we have the long double for extended precision.

22
00:01:46,900 --> 00:01:48,190
At precision.

23
00:01:48,280 --> 00:01:56,860
So as integer types, each floating point representation depends on implementation.

24
00:01:57,280 --> 00:02:06,040
The section won't go into detail about floating point types, but note that there is substantial nuance

25
00:02:06,040 --> 00:02:08,230
involved in these implementations.

26
00:02:09,370 --> 00:02:20,500
On major desktop operating system, the float level usually has four bytes of precision.

27
00:02:20,710 --> 00:02:21,340
Here.

28
00:02:23,670 --> 00:02:24,780
Four bytes.

29
00:02:26,320 --> 00:02:33,970
Uh, the double and long hair levels usually usually have actually eight bytes.

30
00:02:34,000 --> 00:02:37,840
Eight bytes and long double eight bytes.

31
00:02:38,500 --> 00:02:39,520
Eight bytes.

32
00:02:40,740 --> 00:02:47,760
So most users not involved in scientific computing applications can safely ignore the details of floating

33
00:02:47,760 --> 00:02:50,610
point representation in such cases.

34
00:02:50,640 --> 00:02:56,220
A good general rule is to use double.

35
00:02:58,390 --> 00:03:04,210
For those who cannot safely ignore the details, look at the floating point specifications relevant

36
00:03:04,210 --> 00:03:05,950
to your hardware platform.

37
00:03:07,830 --> 00:03:13,050
And let's go to floating point literals.

38
00:03:13,080 --> 00:03:14,940
Floating point literals.

39
00:03:16,300 --> 00:03:16,910
They are.

40
00:03:23,130 --> 00:03:25,350
Floating point literals.

41
00:03:28,750 --> 00:03:29,140
Yeah.

42
00:03:37,570 --> 00:03:38,300
Wires.

43
00:03:38,350 --> 00:03:44,260
And yes, the floating point literals are double precision by default.

44
00:03:44,290 --> 00:03:54,430
If you need a single precision, use an F or uppercase F suffix for extended precision, use L or uppercase

45
00:03:54,460 --> 00:03:58,720
L, as I will show here float A, for example.

46
00:03:58,720 --> 00:04:00,340
0.1.

47
00:04:00,370 --> 00:04:08,080
F double B, for example, 0.2 just A to 0.2.

48
00:04:08,110 --> 00:04:11,220
We don't need to add any literal or suffix.

49
00:04:11,230 --> 00:04:18,640
And lastly, long double long double C equals 0.3 L.

50
00:04:20,310 --> 00:04:24,360
As you can see, we used the uppercase L and uppercase F.

51
00:04:24,810 --> 00:04:28,740
Actually, let's change the comment here so you can see the codes.

52
00:04:29,780 --> 00:04:30,380
So.

53
00:04:33,020 --> 00:04:37,550
And you can also use the scientific notation in literals here.

54
00:04:38,480 --> 00:04:42,500
Here double, for example, planks.

55
00:04:43,900 --> 00:04:45,070
Banks constant.

56
00:04:46,630 --> 00:04:49,870
The Planck's constant.

57
00:04:50,230 --> 00:04:52,540
The Planck's constant is six point.

58
00:04:53,460 --> 00:04:58,860
626074004

59
00:04:58,860 --> 00:05:02,250
and E -34.

60
00:05:03,000 --> 00:05:06,560
So you might be wondering, what is this, though?

61
00:05:06,560 --> 00:05:15,000
So no space here are permitted between the significant the base and the suffix, the potential portion

62
00:05:15,000 --> 00:05:17,460
and the E for 34.

63
00:05:18,710 --> 00:05:29,600
So that's why we didn't use any suffixes or like any space or literal to use for separation of these

64
00:05:29,600 --> 00:05:32,410
codes, these values.

65
00:05:32,420 --> 00:05:39,380
So the floating point format, specifiers, we have format specifiers for printing the these numbers

66
00:05:39,380 --> 00:05:40,490
on console.

67
00:05:40,730 --> 00:05:50,840
So the format specifier F displays a float with decimal digits, whereas here e.

68
00:05:51,880 --> 00:05:54,550
Displays the same number in scientific notation.

69
00:05:54,730 --> 00:06:03,940
You can let Printf decide which of these two to use with the formats specifier which selects the more

70
00:06:03,940 --> 00:06:07,930
compact of E or F for double.

71
00:06:07,930 --> 00:06:09,700
You simply depend on l.

72
00:06:09,730 --> 00:06:21,460
Lowercase l here to describe desired specifier so for long double you prepend an uppercase l For example,

73
00:06:21,460 --> 00:06:31,870
if you want to want a double with decimal digits, you will specify lf l or l g.

74
00:06:32,280 --> 00:06:32,580
Here.

75
00:06:34,120 --> 00:06:36,400
Now, let me comment here.

76
00:06:36,430 --> 00:06:37,330
Double.

77
00:06:38,710 --> 00:06:39,370
With.

78
00:06:41,850 --> 00:06:47,040
Decimal digits here and.

79
00:06:48,800 --> 00:07:02,270
New world specifier or here with decimal digits, but for a long double you will you will specify long

80
00:07:02,300 --> 00:07:09,710
double double with decimal digits.

81
00:07:10,040 --> 00:07:11,540
Here for long double.

82
00:07:11,570 --> 00:07:23,740
You need to use the uppercase l under under case F and the same uppercase l e or.

83
00:07:25,690 --> 00:07:26,510
LG.

84
00:07:27,340 --> 00:07:37,210
So let's write an example code for this and start and compile and run the program, which I will show

85
00:07:37,210 --> 00:07:42,850
you how this format specifiers work on tables.

86
00:07:43,120 --> 00:07:47,470
So we have the main command main.

87
00:07:48,560 --> 00:07:49,730
A function here.

88
00:07:51,190 --> 00:07:55,180
So we can freely use this as our code.

89
00:07:55,300 --> 00:07:56,530
So double.

90
00:07:57,220 --> 00:08:00,730
And here, uh, 6.0.

91
00:08:02,290 --> 00:08:13,630
221409E 23 which I will explain all of these codes later after compiling and print f.

92
00:08:16,320 --> 00:08:19,560
Uh, for example, Avogadro's number.

93
00:08:23,440 --> 00:08:25,060
Number is.

94
00:08:25,060 --> 00:08:28,330
I will explain all of these codes, of course, here.

95
00:08:30,690 --> 00:08:31,640
L f.

96
00:08:32,450 --> 00:08:34,970
LG and new line near.

97
00:08:35,330 --> 00:08:46,550
Then I will give the three three times the same number but with different format specifiers and n.

98
00:08:47,040 --> 00:08:47,570
N.

99
00:08:48,690 --> 00:08:50,400
Here and.

100
00:08:51,360 --> 00:08:52,740
Was this code here?

101
00:08:52,740 --> 00:08:56,850
And lastly, let's create the float number

102
00:08:57,870 --> 00:09:01,440
9.9..

103
00:09:02,540 --> 00:09:04,430
36.

104
00:09:05,940 --> 00:09:06,420
Here.

105
00:09:06,600 --> 00:09:08,160
Let's print.

106
00:09:08,970 --> 00:09:10,440
Print f.

107
00:09:12,390 --> 00:09:13,320
Hogwarts.

108
00:09:16,380 --> 00:09:17,160
Platform.

109
00:09:20,180 --> 00:09:25,940
Here and e f g new line.

110
00:09:26,180 --> 00:09:35,720
Give this use this format, use this number with different formats specified three times HP, HP, HP

111
00:09:36,110 --> 00:09:36,920
and.

112
00:09:36,920 --> 00:09:39,320
Okay so.

113
00:09:45,070 --> 00:09:46,240
Imprint.

114
00:09:49,840 --> 00:09:54,340
And let's finally compile this code here.

115
00:09:54,370 --> 00:09:55,210
Clear.

116
00:09:56,680 --> 00:09:57,490
U.S.S. Maine.

117
00:09:57,490 --> 00:10:02,550
The ship so called, is compiled using the E option.

118
00:10:02,830 --> 00:10:06,850
Let's save this code firstly with Ctrl save and let's compile it again.

119
00:10:07,540 --> 00:10:08,350
Use this code.

120
00:10:08,350 --> 00:10:08,890
So.

121
00:10:10,220 --> 00:10:10,880
Okay.

122
00:10:12,360 --> 00:10:13,020
Arson.

123
00:10:14,840 --> 00:10:15,320
Yes.

124
00:10:15,320 --> 00:10:20,750
So as you can see here, let me okay.

125
00:10:20,750 --> 00:10:32,570
So as you can see here, the first we did the program declares a double here, double called N the format

126
00:10:32,570 --> 00:10:33,680
specifier.

127
00:10:33,710 --> 00:10:36,110
The format specifier L e.

128
00:10:37,390 --> 00:10:41,590
Gives you a scientific notation of this number.

129
00:10:41,590 --> 00:10:44,500
So let's see what this first.

130
00:10:45,350 --> 00:10:46,010
Gave us.

131
00:10:46,040 --> 00:10:49,670
This is the scientific notation which we used as E.

132
00:10:51,290 --> 00:10:52,460
Is the scientific notation.

133
00:10:52,670 --> 00:10:54,050
The program gives us.

134
00:10:54,230 --> 00:10:56,840
And the second we did here.

135
00:11:00,910 --> 00:11:07,300
Gives the decimal representation of this e n number.

136
00:11:07,810 --> 00:11:13,240
As you can see, this gave us the very long decimal representation of this number.

137
00:11:13,870 --> 00:11:15,280
The last one.

138
00:11:17,250 --> 00:11:18,270
Specifier.

139
00:11:18,510 --> 00:11:24,780
The chooses the scientific notation of these, as you can see here.

140
00:11:26,980 --> 00:11:33,040
This notation gave us almost the same e and number, so.

141
00:11:34,310 --> 00:11:44,210
And here we as you know, we created the plot called each p this produce similar printf output using

142
00:11:44,210 --> 00:11:49,850
the E and F specifiers, as you can see here.

143
00:11:53,100 --> 00:11:56,140
But the format specifier here.

144
00:11:56,160 --> 00:11:57,900
Format specifier Here.

145
00:11:58,560 --> 00:12:07,970
Decided to provide the decimal representation of 9.76 rather than the scientific notation.

146
00:12:08,120 --> 00:12:10,700
As a general, you'll use the G.

147
00:12:12,010 --> 00:12:15,460
Print floating point types.

148
00:12:17,790 --> 00:12:21,630
The next lecture will be about the character types.

149
00:12:21,690 --> 00:12:24,090
And I'm waiting you in the next lecture.
