Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: >>: Exceptions vs NaN/NaI



On 2012-04-20 08:15:12 -0700, Dmitry Nadezhin wrote:
> Now ExtendedRational is total-ordered type (it implements
> Java interface Comparable). I don't like an idea to add NaN
> to ExtendedRational, because it will loose total order. And
> now I try to understand if I will be forced to add NaN.
> 
> Shortly speeking, NaN is not necessary for implementations
> that throw language exceptions instead of return NaN.

After thinking a bit more about this, I agree with your arguments.
Now, they can be reversed: I'm mainly wondering why the Java
interface Comparable needs a total-ordered type. For a language
with exceptions, total-ordering is not necessary: if a comparison
is called on two arguments that are unordered, an exception could
be thrown instead of getting an element of {negative,0,positive}.
Wouldn't an interface like this one be sufficient for your
ExtendedRational type?

How about defining ExtendedRationalWithNaN which would have
ExtendedRational as a subclass, in order to get the Comparable
interface on non-NaN datums?

How it seems that the semantics of interface Comparable is more
like IEEE 754 totalOrder than a really numeric comparison:

http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html#compareTo%28java.lang.Double%29

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)