why IEEE floating point number calculate exponent using a biased form?

前端 未结 1 578
再見小時候
再見小時候 2020-12-15 23:39

let\'s say, for the float type in c, according to the IEEE floating point specification, there are 8-bit used for the fraction filed, and it is calculated as first

相关标签:
1条回答
  • 2020-12-16 00:28

    The purpose of the bias is so that the exponent is stored in unsigned form, making it easier to do comparisons. From Wikipedia:

    By arranging the fields so the sign bit is in the most significant bit position, the biased exponent in the middle, then the mantissa in the least significant bits, the resulting value will ordered properly, whether it's interpreted as a floating point or integer value. This allows high speed comparisons of floating point numbers using fixed point hardware.

    So basically, a floating point number is:

    [sign] [unsigned exponent (aka exponent + bias)] [mantissa]
    

    This website provides excellent information about why this is good - specifically, compare the implementations of floating point comparison functions.

    Also, no complete answer about floating point oddities can go without mentioning "What Every Computer Scientist Should Know About Floating-Point Arithmetic." It's long, dense and a bit heavy on the math, but it's long dense mathematical gold (or something like that).

    0 讨论(0)
提交回复
热议问题