Snow Innocent
Snow Innocent

Reputation: 147

Does infinite of floating point number satisfy these equation?

for double or float,

1. -inf < inf == true

2. inf + inf == inf

3. -inf - inf == -inf

4. positive / 0.0 == inf

5. negative / 0.0 == -inf

6. any real number < inf == true

7. -inf < any real number == true

Is this statement true?

We don't know (inf < inf), but we can sure it doesn't throw any exceptions.

Upvotes: 1

Views: 111

Answers (1)

Pascal Cuoq
Pascal Cuoq

Reputation: 80276

All the expressions 1-7 in your question evaluate to true when compiled by a compiler that implements IEEE 754 rules. None of them depend on the rounding mode. For many, this is simply because < and == are exact operations. In addition, -inf - inf is always -inf (that is, in all rounding modes), positive / 0.0 is always +inf, and negative / 0.0 is always -inf.

In 6. and 7. below, it is usual to call the values you refer to “finite” rather than “real”.

  1. any real number < inf == true

  2. -inf < any real number == true

inf < inf always evaluates to false. This, like all the properties 1-7 in your question, should be considered a matter of convention. It was decided to make inf equal to itself, so that it is not strictly less than itself. All these choices are intended to make IEEE 754 arithmetic as useful as possible in practice. In other words, the intention was to have as many algorithms as possible being implementable without having to check explicitly for these special values, and the computation continuing to make sense (when applicable) when they occur. When the special values do not make sense, of course there is always the possibility to test for them.

Upvotes: 5

Related Questions