The witness implementations to allow operator usage are very stylized a boilerplate pattern:
public static final __witness Numerical<NUM_TYPE> NUM =
new Numerical<NUM_TYPE>() {
public NUM_TYPE add(NUM_TYPE addend,
NUM_TYPE augend) {
return NUM_TYPE.add(addend, augend);
}
public NUM_TYPE subtract(NUM_TYPE minuend,
NUM_TYPE subtrahend) {
return NUM_TYPE.subtract(minuend, subtrahend);
}
public NUM_TYPE multiply(NUM_TYPE multiplier,
NUM_TYPE multiplicand) {
return NUM_TYPE.multiply(multiplier, multiplicand);
}
public NUM_TYPE divide(NUM_TYPE dividend,
NUM_TYPE divisor) {
return NUM_TYPE.divide(dividend, divisor);
}
public NUM_TYPE remainder(NUM_TYPE dividend,
NUM_TYPE divisor) {
return NUM_TYPE.remainder( dividend, divisor);
}
public NUM_TYPE plus(NUM_TYPE operand) {
return NUM_TYPE.plus(operand);
}
public NUM_TYPE negate(NUM_TYPE operand) {
return NUM_TYPE.negate( operand);
}
};
where NUM_TYPE is numerical type where operators are useful and
NUM_TYPE.$METHOD_NAME($OPERANDS)
are calls into _static_ methods defined on the NUM_TYPE class.
It would be helpful to explore techniques to avoid writing this code explicitly, or even having to IDE-generated.
public static final __witness Numerical<NUM_TYPE> NUM =
new Numerical<NUM_TYPE>() {
public NUM_TYPE add(NUM_TYPE addend,
NUM_TYPE augend) {
return NUM_TYPE.add(addend, augend);
}
public NUM_TYPE subtract(NUM_TYPE minuend,
NUM_TYPE subtrahend) {
return NUM_TYPE.subtract(minuend, subtrahend);
}
public NUM_TYPE multiply(NUM_TYPE multiplier,
NUM_TYPE multiplicand) {
return NUM_TYPE.multiply(multiplier, multiplicand);
}
public NUM_TYPE divide(NUM_TYPE dividend,
NUM_TYPE divisor) {
return NUM_TYPE.divide(dividend, divisor);
}
public NUM_TYPE remainder(NUM_TYPE dividend,
NUM_TYPE divisor) {
return NUM_TYPE.remainder( dividend, divisor);
}
public NUM_TYPE plus(NUM_TYPE operand) {
return NUM_TYPE.plus(operand);
}
public NUM_TYPE negate(NUM_TYPE operand) {
return NUM_TYPE.negate( operand);
}
};
where NUM_TYPE is numerical type where operators are useful and
NUM_TYPE.$METHOD_NAME($OPERANDS)
are calls into _static_ methods defined on the NUM_TYPE class.
It would be helpful to explore techniques to avoid writing this code explicitly, or even having to IDE-generated.
- relates to
-
JDK-8338529 Initial iteration of numerics modeling interfaces
-
- Resolved
-
-
JDK-8376250 Upgrade Bfloat16 to use operators
-
- Resolved
-
-
JDK-8376823 Add prototype polynomial class
-
- Resolved
-