Re: Exceptions vs NaN/NaI
Dmitri, Michel, P1788
On 8 May 2012, at 04:32, Michel Hack wrote:
> Dmitri Nadezhin wrote:
>> Unfortunately, such compareTo is inconsistent
>> with comparison operations "==", "<", ">", "<=", ">=" :
>> d == Double.NaN is always false;
>> d < Double.NaN is always false;
>> but
>> compare(Double.NaN, Double.NaN) == 0;
>> compare(0.0, Double.NaN) == -1 .
>> This inconsistence is unavoidable with 754-types.
>
> This is not an inconsistency or flaw with 754 -- it is quite
> deliberate, if "compare()" is indeed defined to be TotalOrder.
> You should also have
> compare(-0.0, +0.0) == -1
> but
> -0.0 == +0.0
>
> The fact that NaN compares Unequal to anything, including itself,
> is a deliberate FEATURE of 754...
Michel knows more than I about these things, but FWIW I agree with everything he says here, in particular about the advantages of NaN in parallel computations.
Making an interval type fully conforming lets it be plugged into an arbitrary interval program, in place of some other interval type, with the knowledge that the program will still run and produce valid results. Dmitri, is that not worth while? It means that your package, instead of belonging to a limited "rational intervals community", with maybe limited life span, would become usable worldwide as long as the 1788 standard lasts.
Would it be possible to ask the architects of the JVM to provide a "ComparablePlusNaN" interface? It would, I guess, not be hard to design, as the NaN aspect would conform to the 754 spec.
John