compareTo method
- Object other
override
Returns a negative integer if this
less than other
,
a positive integer if this
greater than other
,
and zero if this
and other
are equal.
Implementation
@override
int compareTo(Object other) {
if (other is! SignMagnitudeValue) {
throw RohdHclException('Input must be of type SignMagnitudeValue');
}
if (!value.isValid | !other.value.isValid) {
throw RohdHclException('Inputs must be valid.');
}
final maxWidth = max(width, other.width);
final val1 = magnitude.zeroExtend(maxWidth);
final val2 = other.magnitude.zeroExtend(maxWidth);
if (sign == other.sign) {
return val1.compareTo(val2) * ((sign == LogicValue.one) ? -1 : 1);
} else {
// different signs, negative is less than positive
return sign == LogicValue.one ? -1 : 1;
}
}