13 Jul 1998 23:39:09 -0400

Related articles |
---|

[2 earlier articles] |

Re: Is infinity equal to infinity? rwhutch@nr.infi.net (1998-07-10) |

Re: Is infinity equal to infinity? fis@mpi-sb.mpg.de (Matthias Fischmann) (1998-07-10) |

Re: Is infinity equal to infinity? john_mitchell@intuit.com (John Mitchell) (1998-07-10) |

Re: Is infinity equal to infinity? joachim.durchholz@munich.netsurf.de (Joachim Durchholz) (1998-07-10) |

Re: Is infinity equal to infinity? bear@sonic.net (Ray Dillinger) (1998-07-11) |

Re: Is infinity equal to infinity? Kevin@quitt.net (1998-07-11) |

Re: Is infinity equal to infinity? dwcantrell@aol.com (1998-07-13) |

Re: Is infinity equal to infinity? dwcantrell@aol.com (1998-07-13) |

Re: Is infinity equal to infinity? henry@spsystems.net (1998-07-13) |

Re: Is infinity equal to infinity? erikr@iar.se (Erik Runeson) (1998-07-20) |

Re: Is infinity equal to infinity? larry.jones@sdrc.com (Larry Jones) (1998-07-20) |

Re: Is infinity equal to infinity? darcy@usul.CS.Berkeley.EDU (1998-07-20) |

Re: Is infinity equal to infinity? darcy@usul.CS.Berkeley.EDU (1998-07-20) |

[4 later articles] |

From: | dwcantrell@aol.com (DWCantrell) |

Newsgroups: | comp.compilers |

Date: | 13 Jul 1998 23:39:09 -0400 |

Organization: | AOL http://www.aol.com |

References: | 98-07-058 |

Keywords: | arithmetic |

Erik Runeson <erikr@iar.se> writes:

*>When comparing floating-point numbers, should infinity (Inf) be*

*>concidered equal to infinity?*

Should +oo be considered equal to itself? The question is not entirely

trivial. Perhaps the answer depends on what +oo is used to represent

in a given floating-point implementation.

*>Inf == Inf ?*

*>*

*>The IEEE 754 standard for floating-point arithmetics does not say*

*>anything about this case,*

Technically true. The standard says:

Four mutually exclusive relations are possible: "less than," "equal,"

"greater than," and "unordered." The last case arises when at least

one operand is NaN. Every NaN shall compare unordered with

everything, including itself.

[Mathematicians reading this should bear in mind (1) that a NaN, abbrev.

for "Not a Number," can occur in several ways, e.g. as the result of

certain invalid operations such as 0/0, but (2) that, in the standard, +oo

and -oo are definitely NOT considered to be NaNs.]

However, if the second sentence quoted above is taken to mean that the

last case arises when *and only when* at least one operand is NaN, then

the standard requires that +oo = +oo be TRUE.

To remove doubt as to the intent: In an implementation guide to a draft

version of the standard, Coonen [_Computer_, 13: 1, p. 78] gives a table

which clearly shows that +oo = +oo and -oo = -oo are to be TRUE.

*> but a similar case is: Inf - Inf = NaN*

*>*

*>Any comparison with a NaN (Not a number) shall, according to the IEEE*

*>754 be concidered unordered and return false.*

Not quite. If you think of such predicates as "unequal" and "unordered"

itself as being comparisons, then they must be TRUE when at least

one operand is NaN. I expect you meant specifically that "equal" must

be FALSE in such a case, which is correct.

*>I believe that comparing Inf with Inf should also be unordered, but this*

*>is not how it is implemented in e.g GCC.*

*>*

*>Any comments?*

The standard states that

Infinity arithmetic shall be construed as the limiting case of real

arithmetic with operands of arbitrarily large magnitude, when such a

limit exists. Infinities shall be interpreted in the affine sense, that is,

-oo < (every finite number) < +oo.

This *seems* to make it clear that the infinities of the standard represent

the two improper elements of the extended real number system. And

although many mathematicians may warn that +oo is not actually a

number, they should still agree that +oo = +oo is TRUE in the extended

real number system.

But +oo is *also* used to represent overflow quite often! Then it does not

represent the +infinity of the extended reals, but rather *any finite* number

which exceeds the format's largest finite number. In this case, surely +oo

should be treated as if it were NaN. Perhaps a quote from Knuth [_The Art

of Computer Programming_, 2nd ed., v. 2, p. 593] would be appropriate:

If oo is being used to suggest overflow, it is incorrect to let 1/oo be

equal

to zero, lest inaccurate results be regarded as true answers. It is far

better to represent overflow by (0/0), and to adhere to the convention that

the result of any operation is undefined if at least one of the inputs is

undefined. This type of overflow indication has the advantage that final

results of an extended calculation reveal exactly which answers are

defined and which are not.

(I do not know if there is a similar passage in the 3rd ed.)

Let us now distinguish here between overflows, calling them +OF and -OF,

and the infinities of the extended reals, calling them +oo and -oo. Then I

think that ideally we should have -oo < -OF < x < +OF < +oo for all finite

numbers x representable in the format, +oo = +oo, etc. But +OFs should

be unordered with respect to each other, etc. (In fact, *ideally* I think that

+OF = +OF should be considered as neither TRUE nor FALSE, but rather

as INDETERMINATE.)

I hope this helps.

Cheers,

David Cantrell

--

Post a followup to this message

Return to the
comp.compilers page.

Search the
comp.compilers archives again.