Search code examples
floating-pointieee-754

Round to Nearest in IEEE 754


In IEEE 754 there is a "Round to Nearest" method of rounding floating point values.

But I do not understand one item in that definition:

If the two nearest representable values are equally near, the one with its least significant bit zero is chosen

What is "least significant bit zero is chosen"


Solution

  • It looks like I understood the issue. Single and Double precission numbers can be represented as 32 and 64 sequence of bits with the following way:

    b bbbbbbbb bbbbbbbbbbbbbbbbbbbbbbb
    
    b bbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    

    Here b is zero or one. First group corresponds to sign of a number. Second group corresponds to exponent of a number and consist of 8 (single precission) and 11 (double precision) bits. Third group corresponds to mantissa of a number and consist of 23 (single precission) and 52 (double precision) bits.

    Hence, the least significant bit of a number is 23d bit of mantissa for single precission number and 52d bit of mantissa for double precission number. This is the rightmost bit of a number. If this bit is zero it will be chosen.

    Note: Even and odd numbers are defined only for integer values. Hence, if rounding function rounds numbers only to integer values this rule degenerates to round-to-even rule

    Thanks to everyone for your efforts.