2

When dealing with floating point numbers, is there every a time when adding two non-negative, finite, non-NaN numbers will result in a result that is less than the greater of the two? $x + y < max(x, y)$. My gut feeling is no, but I know floating point numbers are complicated.

Captain Man
  • 123
  • 5

1 Answers1

2

No. Addition in IEEE-754 floating point a fairly simple process:

  1. Compute the true mathematical sum of the two input operands.

  2. Round the true sum to the nearest representable normal number, ignoring limits on the exponent for the moment.

  3. If the exponent is larger than the largest allowed exponent, return infinity with the correct sign.

  4. If the exponent is smaller than the smallest allowed exponent, round to the nearest subnormal representation.

The only part of this process that could go downwards to result in a smaller number is the rounding step. However, since both inputs are representable by definition, this rounding step can't possibly result in a number smaller than the input.

orlp
  • 13,988
  • 1
  • 26
  • 41