Saturday, January 6, 2024

Floating point bias

To facilitate comparison, floating point store the sign in fist speed follow by exponent bits. The exponent is stored as two’s compliment number. 

An unsigned integer of 8 bits cover the value of 0 to 255. Two’s compliment encoding divide the 256 values into (almost) half for positive and half for negative. The advantage of two’s compliment number is that we can just add positive and negative number without heeding the sign and still generate the correct result. 

As exponent is stored as two’s compliment, the value of negative is higher ( in binary format) than positive exponent. To allow correct comparison, ieee754 uses a bias of 127. The bias was added to the exponent before it is stored. So the comparison would be performed naturally. 

When the floating point is used for computation, the bias is subtracted from the exponent before use 

No comments: