Alterna · learning material
10.1 How to record the final number of bits
The computer has no infinite number of numbers. The number is recorded by the sign, the scale, and the significant bits; some values will have to be rounded.
What this material covers
- End bits instead of arbitrary accuracy
Content and key concepts
The network consists of arrays of numbers and amounts of works.
The computer has no infinite number of numbers. The number is recorded by the sign, the scale, and the significant bits; some values will have to be rounded.
The numbers have final accuracy; they have to be stored and moved. The matrix blocks produce a lot of independent work, but memory and group organization also affect the results.
Для изменения рисунка включитеJavaScript; расчёт и теория доступны далее.
End bits instead of arbitrary accuracy
An important number of the formula and its machine representation are different objects. In the binary floating point, the sign is stored, the field exponent E and the whole fraction F. For a normal number with f fractional bits and bias displacement:
x
=
(
−
1
)
s
(
1
+
F
2
f
)
2
E
−
b
i
a
s
.
x=(-1)^s\left(1+\frac{F}{2^f}\right)2^{E-\mathrm{bias}}.
x
=
(
−
1
)
s
(
1
+
2
f
F
)
2
E
−
bias
.
For FP32 the fields are dimensions 1/8/23, bias127. B -192=1.5×27 receive s=1,E=134,F=222. The original unit of normal significand is not kept separately.
For E=0 rules, others are: subnormal is equal to (-1)s(F/2\f)2\(1-bias) without a hidden unit. For F=0 is signed zero. Maximum E is reserved for infinity and NaN: for Infinity fraction0, NaN has a non-zero.
Experiment.
Enter -192, then -0, then change the format. The individual bit editor allows you to change the sign/exponent/fraction and see decoded. Special valutes are displayed with an explanation; NaN is not given for the correct result of the subsequent calculation.
Boundary.
The entry first becomes JavaScript Number (binary64). The Codec rounds this particular value into the chosen format rather than the exact arbitrary decimal rational number. For example, 1 is no longer accurately represented by the format 64. The signature of the format does not turn all the calculation of the page into FP16.
import struct
bits=struct.unpack('>I',struct.pack('>f',-192.0))[0]
assert bits>>31==1
assert (bits>>23)&255==134
assert bits&((1<<23)-1)==1<<22
The code repeats the operations just taken care of.
Completely checked Python-example Chapter
Available with a separate file; the short piece shown does not replace its implementation.
For encoded exponent0, another rule is used without hidden.
Size of recording and accuracy. How does this question continue the result?
Python examples of Chapter 10
Academic base