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(this.m, other.m);
final n = max(this.n, other.n);
final val1 = expandWidth(sign: s, m: m, n: n);
final val2 = other.expandWidth(sign: s, m: m, n: n);
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;
}
}