operator - method
Override the subtraction operator to manage the Temperature/TemperatureInterval
relationship.
- Subtracting a
TemperatureInterval
returns aTemperatureInterval
object. - Attempting to subtract a
Temperature
from aTemperatureInterval
throws a QuantityException as a physically nonsensical operation.
Implementation
@override
Quantity operator -(dynamic subtrahend) {
if (subtrahend is TemperatureInterval) {
final newValueSI = valueSI - subtrahend.valueSI;
final ur = Quantity.calcRelativeCombinedUncertaintySumDiff(
this, subtrahend, newValueSI);
return TemperatureInterval(K: newValueSI, uncert: ur);
} else if (subtrahend is Temperature) {
throw const QuantityException(
'Subtracting a Temperature from a TemperatureInterval is not supported.');
} else {
return super - subtrahend;
}
}