CS 208 w20 lecture 7 outline
1 Quiz
- Common mistakes: applying little endian, data type widths, pointers as data
- Average score 25.6, median score 27
- Good: practice problems, discussing with neighbors, course web page
- Comments: more C in class, book can be challenging
2 Poll
- How would the bits of
0x8a000000
be interpreted as anint
and afloat
? Can express in terms of powers of two.- \(-2^{31} + 2^{27} + 2^{25} = -59 \times 2^{25}\)
- \(-1 \times 2^{-107}\)
- We execute the following code in C. How many bytes are the same (value and position) between
i
andf
?
int i = 384; // 2^8 + 2^7 float f = (float) i;
i
is0x00 00 01 80
- 384 =
0b1 1000 0000
= \(2^8 \times 1.1\)s
= 0exp
= \(E + Bias = 8 + 127 = 135 =\)0b1000 0111
frac
= \(M - 1 =\)0b100...0
0b0100 0011 1100 0000 0000 0000 0000 0000
f
is0x43 c0 00 00
3 Floating point wrap-up
- Denormalized: evenly spaced numbers close to 0 (when
exp
bits are all zero) - Normalized: exponentially spaced numbers outside of denormalized range (when
exp
bits ≠ 0 and are not all 1s)
Key trade-off vs fixed-point: IEEE achieves far greater precision near zero and an order of magnitude greater range at the expense of less precision farther away from 0. With a 64-bit double, the values at which this loss of precision becomes significant are so large as to arise very rarely in practice. Conversely, very small values occur in all sorts of practical applications, making the extra precision there very valuable in approximating real arithmetic.