Michael Jung (
[email protected]) wrote:
: > Suppose there were an ExtendedBigDecimal with the following properties:
: >
: > 1. Its value set is the union of BigDecimal and the Double infinities
: > and NaNs.
: >
: > 2. It is Comparable<ExtendedBigDecimal>, with natural order for number
: > to number comparisons, and the Double.compareTo rules for infinities and
: > NaNs.
: >
: > Then I think every value in the java.lang and java.math concrete Number
: > subclasses is exactly convertible to ExtendedBigDecimal, with the
: > ExtendedBigDecimal compareTo consistent with the Number class' compareTo.
: >
: > Suppose also there were an interface, EBDNumber, that has a single
: > abstract method:
: >
: > ExtendedBigDecimal convertToEBD();
: >
: > and EBDNumber also extended Comparable<EBDNumber>
: >
: > The comparison would be implemented by the Number subclass compareTo
: > methods not giving up after finding the other object is of a different
: > class. First it would check for it also implementing EBDNumber, and if
: > so convert both numbers to ExtendedBigDecimal and use its compareTo.
: >
: > Two questions:
: >
: > 1. Does this make any sense?
: >
: > 2. Would the mixed type comparisons it would support be sufficiently
: > useful to justify the cost.
: >
: > Note that it would not help with e.g. general rational number
: > arithmetic. 1/3, in a rational number package, would not be exactly
: > convertible to ExtendedBigDecimal.
: As I see it, it all boils down to, for what purpose we extend Number. We have
: already seen that we lose all extensions of number that don't want to/should
: be compared, such as the complex, finite subsets, etc.
: So, if I design a number class that should be internally comparable, would I
: want this to be comparable to ExtendedBigDecimal?
: Say, I like fractions a lot and have "class Fractions { BigDecimal nominator;
: BigDecimal numerator; }" with lots of funky methods. I can even compare
: them. Would I bother to write a method that converts (literally) a fraction of
: my numbers to EBDs. What do I do with the rest?
: Michael
Yes, and other perfectly reasonable examples could be invented in which
comparisons could not necessarily be made at all.
Imagine an astronomy application that compares the timing of events. A
star explodes and later events like a dust cloud are caused by the
explosion and the timing of the events can be compared. But the timing of
events outside of some "local" region of the original star cannot be
compared to the first star at all, it has no meaning.
Or numbers that represent survey distances on the earth. Depending on the
geometric models and the distances involved, some measurements cannot be
compared to one another.
$0.10