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! FixedPointValue) {
throw RohdHclException('Input must be of type FixedPointValue');
}
if (!value.isValid | !other.value.isValid) {
throw RohdHclException('Inputs must be valid.');
}
final s = signed | other.signed;
final m = max(integerWidth, other.integerWidth);
final n = max(fractionWidth, other.fractionWidth);
final val1 =
FixedPointValue.populator(integerWidth: m, fractionWidth: n, signed: s)
.widen(this)
.value;
final val2 =
FixedPointValue.populator(integerWidth: m, fractionWidth: n, signed: s)
.widen(other)
.value;
final comp = val1.compareTo(val2);
if (comp == 0) {
return comp;
} else if (!isNegative() & !other.isNegative()) {
return comp;
} else if (!isNegative() & other.isNegative()) {
return 1;
} else if (isNegative() & !other.isNegative()) {
return -1;
} else {
return -comp;
}
}