Re: Infinity (to the nearest integer)
"Karp, Alan H" <[email protected]>
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <A0BE9926384D0940BBAD4B60190CB29A71814B609F@GVW0433EXB.americas.hpqcorp.net> |
Thomas Leonard wrote: > > This is a bit surprising... > > ? Infinity.round() > # value: 9223372036854775807 > > ? NaN.floor() > # value: 0 > It is to me, too. According to http://docs.sun.com/source/806-3568/ncg_goldberg.html#918 "The rule for determining the result of an operation that has infinity as an operand is simple: replace infinity with a finite number x and take the limit as x goes to infinity." Similarly, a NaN poisons everything it touches. If A is a NaN, then A op B = A unless B is a NaN in which case the result is either A or B. The question then becomes, how do you implement round() and floor(). They are normally implemented as bit operations on the contents of the registers, but these MUST be mathematically equivalent to an implementation based on arithmetic operations on floating point numbers. The above results indicate that this equivalence has been violated. ________________________ Alan Karp Principal Scientist Virus Safe Computing Initiative Hewlett-Packard Laboratories 1501 Page Mill Road Palo Alto, CA 94304 (650) 857-3967, fax (650) 857-7029 http://www.hpl.hp.com/personal/Alan_Karp