RFR: 8338529: Initial iteration of numerics modeling interfaces [v3]

John R Rose jrose at openjdk.org
Sat Jan 17 00:27:09 UTC 2026


On Fri, 16 Jan 2026 20:50:42 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> A refinement of some earlier ideas on the numerics modeling interfaces to inform further discussions.
>> 
>> This is a "lumpy" rather than "splitty" design in terms of favoring a smaller number of interfaces with more functionality rather than a larger number of interfaces making smaller distinctions.
>> 
>> Various design comments and to-do's noted in the code.
>
> Joe Darcy has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Add default methods.
>  - Respond to review feedback; add default methods.

interface Orderable<T> {

enum Order { LT, GT, EQ, UO };  //or use a couple int-bits

/** Return LT if x definitely precedes y.
 * Return GT if y definitely precedes x.
 * Return EQ if x and y are equivalent <i>in this particular order</i>
 * Return UO otherwise
 * Conformance rules are as follows.
 * Symmetry: If order(x,y)==LT (resp. GT, EQ, UO)  then also order(y,x)==GT (resp. LT, EQ, UO)
 * Reflexivity: Always order(x,y)==EQ or UO, never GT or LT.
 * Transitivity: If order(x,y)==LT or EQ and order(y,z)==LT or EQ, then order(x,z)==LT or EQ, but cannot be EQ if both previous were EQ.
 */
abstract Order order(T x, T y);
// This is enough to drive a sort algorithm with care, even though it’s just partial.

/**
 * Returns true if this order never reports UO for any input.
 * True for integers and anything comparable or having a comparator.
 * False for FP types (because of NaN elements).
 * False for partially ordered data types, if not totalized.
 */
abstract boolean isTotal();

/**
 * If this returns true for two x and y, then order(x,y) is not UO.
 */
default boolean isTotal(T x) {
  return isTotal() || order(x,x) != UO;
}

// Could do similar query to detect the less interesting case of
// orders which are coarser than operator==, but that’s only
// true with +0.0 vs. -0.0.

default boolean lt(T x, T y) { return order(x,y) == LT; }
default boolean le(T x, T y) { return lt(x,y) || eq(x,y); }
//... and so forth for gt, ge, eq, ne

default boolean min(T x, T y) { return lt(x,y) ? x : y; }
//... and so forth
}

-------------

PR Comment: https://git.openjdk.org/valhalla/pull/1917#issuecomment-3762325873


More information about the valhalla-dev mailing list