Lecture 6: Floating Point¶
Warning
"95% of the folks out there are completely clueless about floating point".
– James Gosling, 1998-02-28
上课时我爱搭不理,做作业发现要逐帧学习🤡
- Andrew Joker Hu🐷
现在才发现课前这句话说的太对了,Lecture 6 是目前为止我认为最难的一节课,也在课后花费很多时间才将其完全弄清楚
这一节的笔记风格切换回“国内课堂”,跳过前言和引入,以及思维指导,我们直接上结论:
C | |
---|---|
1 |
|
We know the bias
= -(2^(k-1)-1)
= -127
Signal Bit
is1
, so-
1000 0001
is theexponent
, which is129
in decimal, so2^(129-127) = 2^2 = 4
Significand
equals to0.111
So the result is (-1) * (4) * (1.111)_2
= -7.5
Special Presentation¶
Representation for 0¶
C | |
---|---|
1 2 3 4 |
|
exponent
all zeroessignificand
all zeroes
Representation for Not a Number¶
What do I get if I calculate sqrt(-4.0)
or 0/0
?
- If ∞ not an error, these shouldn’t be either
- Called
Not a Number (NaN)
Exponent
= 255,Significand
equals to nonzero
Representation for Denorms¶
Problem: There’s a gap among representable FP numbers around 0
Smallest representable pos num:
\(a = {1.000...000}_2 * 2^{-126} = 2^{-126}\)
Second smallest representable pos num:
\(b = {1.000...001}_2 * 2^{-126} = 2^{-126} + 2^{-149}\)