In modern computers, data is primarily stored in binary format, with integers being the most straightforward and well-understood type of data for computational tasks. To handle different types of calculations, many computers are equipped with both a main processor and a coprocessor. The main processor typically focuses on integer calculations, while the coprocessor specializes in floating-point arithmetic.
During the era of x86-16 architecture, the 8088 CPU and the 8087 coprocessor were commonly used together. The 8088 handled integer-based calculations, and the 8087 was employed to assist with floating-point operations. This division of labor allowed for more efficient and faster computations.
before we go, we need to know what is exponential notation
Exponential Notaion
Exponential notation is a method used for normalizing data. For instance, the number127.3424
can be represented as1.273424 * e+2
, where1.273424
is the mantissa and10^2
is the exponent.
breaking down how 127.3424
is stored as a Float32
The integer part 127(10)
in decimal is equivalent to 01111111(2)
in binary.
The fractional part 0.3424(10)
in decimal can be approximated as 0.010101....(2)
in binary.
Combining these, the binary representation becomes 1111111.010101....(2)
Upon normalization, the number becomes 1.111111010101…*2^6
.
1.111111010101...
2^6
, but we only store 6
since it's understood that this is a binary exponent.What Is Bias?
The exponent can be either positive or negative. For instance, if the original data is less than 1, the exponent could be negative like2^-6
(we only store -6 on the memory). This is where bias (typically127
for float32) comes into play.
Adding 127
to the exponent 6
, we get 133
, which in binary is 10000101
.
0
and 127
, the actual exponent is negative.128
and 255
, the actual exponent is positive.In the end, the float32 representation would be:
0
10000101
11111101010101010101010
, truncated to fit the 23-bit field for float32.This provides an approximate but efficient representation of the number 127.3424
in IEEE 754 float32 format.