Search code examples
floating-pointieee-754

Does IEEE 754 guarantee exact representation for operations on whole numbers that fit in mantissa?


From what I can gather, whole numbers that can be fit in the mantissa of a floating point number are represented exactly:

Can a IEEE 754 real number "cover" all integers within its range?

My question is:

  • Given 2 floating point whole numbers that are exactly represented,
  • does an operation (+,-,/,*) on the 2 numbers always produce an exactly represented floating point number
  • so long as the result is in the exactly representable range?

In other words, is there ever a time when floating point 2.0 * 3.0 != 6?


Solution

  • Yes, this falls out from the requirement that the basic operations are correctly rounded. Since the result is exactly representable it is also the correctly rounded result.