compareTo method

int compareTo(
  1. PolyFit that
)

Compare lexicographically.

Implementation

int compareTo(PolyFit that) {
  var EPSILON = 1E-5;
  var maxDegree = math.max(polyDegree(), that.polyDegree());
  for (var j = maxDegree; j >= 0; j--) {
    var term1 = 0.0;
    var term2 = 0.0;
    if (polyDegree() >= j) term1 = beta[j][0];
    if (that.polyDegree() >= j) term2 = that.beta[j][0];
    if (term1.abs() < EPSILON) term1 = 0.0;
    if (term2.abs() < EPSILON) term2 = 0.0;
    if (term1 < term2) {
      return -1;
    } else if (term1 > term2) {
      return 1;
    }
  }
  return 0;
}